Skip to content

LambdaConversionException: Type mismatch for instantiated parameter #23179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
xuwei-k opened this issue May 16, 2025 · 1 comment
Open

LambdaConversionException: Type mismatch for instantiated parameter #23179

xuwei-k opened this issue May 16, 2025 · 1 comment

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented May 16, 2025

Compiler version

  • 3.3.6
  • 3.7.0
  • 3.7.1-RC1
  • 3.7.2-RC1-bin-20250515-c481e91-NIGHTLY

Minimized code

JDK 11 or later

Welcome to Scala 3.7.1-RC1 (11.0.26, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                          
scala> trait A { def f(a: Array[AnyRef]): Any }
// defined trait A
                                                                                                                                          
scala> def g(a: A) = a.f(Array.empty[AnyRef])
def g(a: A): Any
                                                                                                                                          
scala> g((x: Array[? >: AnyRef]) => x.headOption)
java.lang.BootstrapMethodError: bootstrap method initialization exception
  at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:194)
  at java.base/java.lang.invoke.CallSite.makeSite(CallSite.java:307)
  at java.base/java.lang.invoke.MethodHandleNatives.linkCallSiteImpl(MethodHandleNatives.java:258)
  at java.base/java.lang.invoke.MethodHandleNatives.linkCallSite(MethodHandleNatives.java:248)
  ... 66 elided
Caused by: java.lang.invoke.LambdaConversionException: Type mismatch for instantiated parameter 0: class java.lang.Object is not a subtype of class [Ljava.lang.Object;
  at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.checkDescriptor(AbstractValidatingLambdaMetafactory.java:308)
  at java.base/java.lang.invoke.AbstractValidatingLambdaMetafactory.validateMetafactoryArgs(AbstractValidatingLambdaMetafactory.java:294)
  at java.base/java.lang.invoke.LambdaMetafactory.altMetafactory(LambdaMetafactory.java:503)
  at java.base/java.lang.invoke.BootstrapMethodInvoker.invoke(BootstrapMethodInvoker.java:138)
  ... 69 more

JDK 8

Welcome to Scala 3.7.1-RC1 (1.8.0_442, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                          
scala> trait A { def f(a: Array[AnyRef]): Any }
// defined trait A
                                                                                                                                          
scala> def g(a: A) = a.f(Array.empty[AnyRef])
def g(a: A): Any
                                                                                                                                          
scala> g((x: Array[? >: AnyRef]) => x.headOption)
val res0: Any = None

Expectation

compile error or success. don't throw runtime error

Note

Scala 2.13.16

Welcome to Scala 2.13.16 (OpenJDK 64-Bit Server VM, Java 11.0.26).
Type in expressions for evaluation. Or try :help.

scala> trait A { def f(a: Array[AnyRef]): Any }
trait A

scala> def g(a: A) = a.f(Array.empty[AnyRef])
def g(a: A): Any

scala> g((x: Array[? >: AnyRef]) => x.headOption)
val res0: Any = None

Scala 2.12.20

Welcome to Scala 2.12.20 (OpenJDK 64-Bit Server VM, Java 11.0.26).
Type in expressions for evaluation. Or try :help.

scala> trait A { def f(a: Array[AnyRef]): Any }
defined trait A

scala> def g(a: A) = a.f(Array.empty[AnyRef])
g: (a: A)Any

scala> g((x: Array[? >: AnyRef]) => x.headOption)
res0: Any = None
@xuwei-k xuwei-k added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels May 16, 2025
@Gedochao
Copy link
Contributor

out-of-REPL reproduction:

trait A { def f(a: Array[AnyRef]): Any }
def g(a: A) = a.f(Array.empty[AnyRef])
@main def main = {
	g((x: Array[? >: AnyRef]) => x.headOption)
}

@Gedochao Gedochao added area:initialization and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants