Skip to content

Commit 3bca6a2

Browse files
committed
SI-9387 Fix VerifyError introduced by indylambda
As with regular `Apply`-s, we should compute the generated type based on the function's type, rather than the expected type. In the test case, the expected type was void. Now, we correctly use the generated type of `scala/Function1`, which is enough to generate a subsequent POP instruction. The tree shape involved was: ``` arg0 = { { $anonfun() }; scala.runtime.BoxedUnit.UNIT } ```
1 parent b92c3af commit 3bca6a2

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,11 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
632632
case _ =>
633633
abort(s"Cannot instantiate $tpt of kind: $generatedType")
634634
}
635-
case Apply(_, args) if app.hasAttachment[delambdafy.LambdaMetaFactoryCapable] =>
635+
case Apply(fun, args) if app.hasAttachment[delambdafy.LambdaMetaFactoryCapable] =>
636636
val attachment = app.attachments.get[delambdafy.LambdaMetaFactoryCapable].get
637637
genLoadArguments(args, paramTKs(app))
638638
genInvokeDynamicLambda(attachment.target, attachment.arity, attachment.functionalInterface)
639+
generatedType = asmMethodType(fun.symbol).returnType
639640

640641
case Apply(fun @ _, List(expr)) if currentRun.runDefinitions.isBox(fun.symbol) =>
641642
val nativeKind = tpeTK(expr)

test/files/run/t9387.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class G[T]
2+
object G {
3+
def v[T](x: T): G[T] = null
4+
}
5+
6+
class A[T]
7+
object A {
8+
def apply[T](x: => G[T]): A[T] = null
9+
}
10+
11+
object T {
12+
A[Unit](G.v(() => ())) // Was VerifyError
13+
}
14+
15+
object Test {
16+
def main(args: Array[String]): Unit = {
17+
T
18+
}
19+
20+
}

test/files/run/t9387b.check

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

test/files/run/t9387b.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
object T {
2+
val f: Unit = () => ()
3+
println(f)
4+
}
5+
6+
object U {
7+
def f[T](t: T): T = t
8+
f[Unit](() => ())
9+
}
10+
11+
object Test {
12+
def main(args: Array[String]): Unit = {
13+
T
14+
U
15+
}
16+
}

0 commit comments

Comments
 (0)