diff options
author | Sébastien Doeraene <sjrdoeraene@gmail.com> | 2016-03-05 09:51:50 +0100 |
---|---|---|
committer | Sébastien Doeraene <sjrdoeraene@gmail.com> | 2016-03-07 16:18:54 +0100 |
commit | 4b10e2b7127f3644453a00fe54fec0212614c944 (patch) | |
tree | ddc25411d2734004e144d55c9d51231f59d0b795 | |
parent | a50926701ef5171779aa025d2d307751d166cabe (diff) | |
download | dotty-4b10e2b7127f3644453a00fe54fec0212614c944.tar.gz dotty-4b10e2b7127f3644453a00fe54fec0212614c944.tar.bz2 dotty-4b10e2b7127f3644453a00fe54fec0212614c944.zip |
Fix #1146: Fix bug of ExpandSAMs with non-apply SAM methods.
When expanding a SAM, ExpandSAMs always used the name `apply` for
the generated forwarder, instead of the name of the method which
is abstract in the SAM type. This commit fixes this issue.
-rw-r--r-- | src/dotty/tools/dotc/transform/ExpandSAMs.scala | 3 | ||||
-rw-r--r-- | tests/run/non-jvm-sam-non-apply.check | 1 | ||||
-rw-r--r-- | tests/run/non-jvm-sam-non-apply.scala | 11 |
3 files changed, 14 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/transform/ExpandSAMs.scala b/src/dotty/tools/dotc/transform/ExpandSAMs.scala index 5de778fab..fd556b572 100644 --- a/src/dotty/tools/dotc/transform/ExpandSAMs.scala +++ b/src/dotty/tools/dotc/transform/ExpandSAMs.scala @@ -42,8 +42,9 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer => case tpe @ SAMType(_) if isJvmSam(tpe.classSymbol.asClass) => tree case tpe => + val Seq(samDenot) = tpe.abstractTermMembers.filter(!_.symbol.is(SuperAccessor)) cpy.Block(tree)(stats, - AnonClass(tpe :: Nil, fn.symbol.asTerm :: Nil, nme.apply :: Nil)) + AnonClass(tpe :: Nil, fn.symbol.asTerm :: Nil, samDenot.symbol.asTerm.name :: Nil)) } case _ => tree diff --git a/tests/run/non-jvm-sam-non-apply.check b/tests/run/non-jvm-sam-non-apply.check new file mode 100644 index 000000000..b8626c4cf --- /dev/null +++ b/tests/run/non-jvm-sam-non-apply.check @@ -0,0 +1 @@ +4 diff --git a/tests/run/non-jvm-sam-non-apply.scala b/tests/run/non-jvm-sam-non-apply.scala new file mode 100644 index 000000000..e3bfac928 --- /dev/null +++ b/tests/run/non-jvm-sam-non-apply.scala @@ -0,0 +1,11 @@ +// shouldn't result in an abstract method error when run +abstract class NonJVMSam { + def foo(x: Int): Int +} + +object Test { + def main(args: Array[String]): Unit = { + val f: NonJVMSam = x => x + 1 + println(f.foo(3)) + } +} |