blob: 30e3babc7576d48386bdcf27569f165fb76430fb (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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 takes precedence
def statusQuo() = {
import language.implicitConversions
var ok = false
implicit def fun2sam(fun: Int => String): MySam = { ok = true; 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 statusIndy() = {
val className = (((x: Int) => x.toString): MySam).getClass.toString
assert(!(className contains AnonFunClass), className)
assert(className contains LMFClass, className)
}
statusQuo()
statusIndy()
}
|