-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
This is the smallest reproduction I can find - if I cut this example down any further, the problem goes away. If I run the following test:
// Mock.scala
import scala.reflect.macros.Context
class MockParameter[T](value: T)
class MockFunction2[T1, T2, R] {
def expects(x: MockParameter[T1], y: MockParameter[T2]) = "expects"
}
trait Mock {
import language.experimental.macros
import language.implicitConversions
implicit def toMockParameter[T](x: T) = new MockParameter(x)
implicit def toMockFunction2[T1, T2, R](f: (T1, T2) => R) = macro MockImpl.toMockFunction2[T1, T2, R]
}
object MockImpl {
def toMockFunction2[T1: c.WeakTypeTag, T2: c.WeakTypeTag, R: c.WeakTypeTag](c: Context)(f: c.Expr[(T1, T2) => R]) = {
c.abort(c.enclosingPosition, "Something bad happened")
c.universe.reify(null.asInstanceOf[MockFunction2[T1, T2, R]])
}
}// MockTest.scala
class Foo { def twoParams(x: Int, y: Double) = "twoParams" }
object Test extends App {
val m = new Foo
(m.twoParams _).expects(42, 1.23)
}I would expect to receive a "Something went wrong" error on this line:
(m.twoParams _).expects(42, 1.23)Instead, I get "value expects is not a member of (Int, Double) => String".
If I change the line to avoid the implicit conversion:
toMockParam2(m.twoParams _).expects(42, 1.23)Then I do get the "Something went wrong" error as expected. I also get this error if I cut the example down any further (e.g. by avoiding the implicit conversions to MockParameter by changing expects method to take Integer and Double instead.
Reactions are currently unavailable