Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose narrow in reflection API #5951

Closed
scabug opened this issue Jun 19, 2012 · 2 comments
Closed

Expose narrow in reflection API #5951

scabug opened this issue Jun 19, 2012 · 2 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Jun 19, 2012

In ScalaMock, I need to create instances of traits/classes that may contain abstract methods. To do this, I need to know the types of those methods. Right now, I'm using the following trick:

scala> class Outer[T] { trait Inner[T]; def m(): Inner[T] = null }
defined class Outer

scala> val t = typeOf[Outer[Int]]
t: reflect.runtime.universe.Type = Outer[Int]

scala> val m = t.member(newTermName("m"))
m: reflect.runtime.universe.Symbol = method m

scala> m.typeSignatureIn(SuperType(ThisType(t.typeSymbol), t))
res0: reflect.runtime.universe.Type = ()Outer.this.Inner[Int]

described by Martin as:

That looks like an ingenious exploitation of something that was not meant to be used that way. I do not see why it would not work, though. In general, I believe it's better to create an actual val with the proper type that can serve as prefix type.

Unfortunately, this leaves me with a catch-22 - I can't create an instance of that trait without providing implementations of all of its methods. And I can't implement its methods without knowing their types.

Apparently there is a narrow method that does what I need. It would be helpful if it could be added to the reflection API.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 19, 2012

Imported From: https://issues.scala-lang.org/browse/SI-5951?orig=1
Reporter: @paulbutcher
Affected Versions: 2.10.0-M3

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jun 19, 2012

@xeno-by said:
Implemented in scala/scala#751

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.