blob: a13a71e562328bcc28d1906465a0edf8f32420fd (
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 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()
}
|