Skip to content

Commit e5c5948

Browse files
committed
Merge pull request #1147 from sjrd/fix-non-jvm-sam-non-apply
Fix #1146: Fix bug of ExpandSAMs with non-apply SAM methods.
2 parents 8b4f73f + 4b10e2b commit e5c5948

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

src/dotty/tools/dotc/transform/ExpandSAMs.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ class ExpandSAMs extends MiniPhaseTransform { thisTransformer =>
4242
case tpe @ SAMType(_) if isJvmSam(tpe.classSymbol.asClass) =>
4343
tree
4444
case tpe =>
45+
val Seq(samDenot) = tpe.abstractTermMembers.filter(!_.symbol.is(SuperAccessor))
4546
cpy.Block(tree)(stats,
46-
AnonClass(tpe :: Nil, fn.symbol.asTerm :: Nil, nme.apply :: Nil))
47+
AnonClass(tpe :: Nil, fn.symbol.asTerm :: Nil, samDenot.symbol.asTerm.name :: Nil))
4748
}
4849
case _ =>
4950
tree

tests/run/non-jvm-sam-non-apply.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
4

tests/run/non-jvm-sam-non-apply.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// shouldn't result in an abstract method error when run
2+
abstract class NonJVMSam {
3+
def foo(x: Int): Int
4+
}
5+
6+
object Test {
7+
def main(args: Array[String]): Unit = {
8+
val f: NonJVMSam = x => x + 1
9+
println(f.foo(3))
10+
}
11+
}

0 commit comments

Comments
 (0)