diff options
author | Martin Odersky <odersky@gmail.com> | 2017-01-05 16:02:09 +0700 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2017-01-05 18:00:06 +0700 |
commit | aa6ebe938639f07dd6f5612e645f1449f37a86eb (patch) | |
tree | 24d257c1f12d0f5cb9b76102043046e3a904d98a /tests/run/structuralNoSuchMethod.scala | |
parent | 42eb864dc752254fc3b8b0428570fe94aa1dafc7 (diff) | |
download | dotty-aa6ebe938639f07dd6f5612e645f1449f37a86eb.tar.gz dotty-aa6ebe938639f07dd6f5612e645f1449f37a86eb.tar.bz2 dotty-aa6ebe938639f07dd6f5612e645f1449f37a86eb.zip |
Implement structural type member access
New scheme for implementing structural type member access.
Diffstat (limited to 'tests/run/structuralNoSuchMethod.scala')
-rw-r--r-- | tests/run/structuralNoSuchMethod.scala | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/tests/run/structuralNoSuchMethod.scala b/tests/run/structuralNoSuchMethod.scala new file mode 100644 index 000000000..3d33c9d8b --- /dev/null +++ b/tests/run/structuralNoSuchMethod.scala @@ -0,0 +1,23 @@ +import scala.reflect.Projector.reflectiveProjector + +/** Demonstrates limitation of structural method dispatch (in Scala 2.x and dotty). + * The method must be defined at exactly the argument types given in the structural type; + * Generic instantiation is not possible. + */ +object Test { + type T = { def f(x: String, y: String): String } + + class C[X] { + def f(x: X, y: String): String = "f1" + } + + val x: T = new C[String] + + def main(args: Array[String]) = + try println(x.f("", "")) // throws NoSuchMethodException + catch { + case ex: NoSuchMethodException => + println("no such method") + } + +} |