diff options
Diffstat (limited to 'test/files/run/sammy_after_implicit_view.scala')
-rw-r--r-- | test/files/run/sammy_after_implicit_view.scala | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/files/run/sammy_after_implicit_view.scala b/test/files/run/sammy_after_implicit_view.scala new file mode 100644 index 0000000000..a13a71e562 --- /dev/null +++ b/test/files/run/sammy_after_implicit_view.scala @@ -0,0 +1,28 @@ +trait MySam { def apply(x: Int): String } + +// check that SAM conversion happens after implicit view application +object Test extends App { + final val AnonFunClass = "$anon$" + final val LMFClass = "$$Lambda$" // LambdaMetaFactory names classes like this + + // if there's an implicit conversion, it does not takes precedence (because that's what dotty does) + def implicitSam() = { + import language.implicitConversions + var ok = true + implicit def fun2sam(fun: Int => String): MySam = { ok = false; new MySam { def apply(x: Int) = fun(x) } } + val className = (((x: Int) => x.toString): MySam).getClass.toString + assert(ok, "implicit conversion not called") + assert(!(className contains AnonFunClass), className) + assert(className contains LMFClass, className) + } + + // indirectly check that this sam type instance was created from a class spun up by LambdaMetaFactory + def justSammy() = { + val className = (((x: Int) => x.toString): MySam).getClass.toString + assert(!(className contains AnonFunClass), className) + assert(className contains LMFClass, className) + } + + implicitSam() + justSammy() +} |