-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Type inference after erasure uses package private type over public one leading to java.lang.IllegalAccessError
at runtime
#16474
Comments
I have a simple test project for the above code, I can upload it if required. |
Thank you for this report, I've managed to reproduce it locally. It seems to be a regression introduced since 3.2.0. I'll try to provide dependency free minimization soon |
Reproducer // Encrypter.java
package repro;
public interface Encrypter{} // BaseProvider.java
package repro.impl;
import repro.*;
abstract class BaseProvider{} // Case1Provider.java
package repro.impl;
public abstract class Case1Provider extends BaseProvider {} // Case1.java
package repro;
import repro.impl.*;
public class Case1 extends Case1Provider implements Encrypter {
public Case1(){}
} // Case2Provider.java
package repro.impl;
public abstract class Case2Provider extends BaseProvider {} // Case2.java
package repro;
import repro.impl.*;
public class Case2 extends Case2Provider implements Encrypter {
public Case2(){}
} // test.scala
import repro.*
import scala.util.Try
def get(arg: Any): Try[Encrypter] = Try {
val x: Any = 1
arg match
case 1 => new Case1()
case 2 => new Case2()
case _ => throw new RuntimeException(s"Unsupported got $arg")
}
@main def Test =
val result = get(null)
|
One notable difference between 3.2.0 and 3.2.1 is the type infereded for anonymous function of method private final repro.impl.BaseProvider get$$anonfun$1(java.lang.Object); in 3.2.0 it was : private final repro.Encrypter get$$anonfun$1(java.lang.Object); In case if both classes At the time of typer phase anonfun in inferred to be |
java.lang.IllegalAccessError
java.lang.IllegalAccessError
java.lang.IllegalAccessError
at runtime
Bisect points to 824496b |
By joining union types we could previously uncover inaccessible base classes that could lead to access errors at runtime. We now filter out such classes when computing the orDominator. Fixes scala#16474
I don't think 824496b introduced that problem but maybe it was hidden by some obscure type inference difference before. |
By joining union types we could previously uncover inaccessible base classes that could lead to access errors at runtime. We now filter out such classes when computing the orDominator. Fixes #16474
By joining union types we could previously uncover inaccessible base classes that could lead to access errors at runtime. We now filter out such classes when computing the orDominator. Fixes scala#16474
Below is a minimal code fragment to reproduce the problem. It works from Scala 3.0 to Scala 3.2.0 and it breaks with Scala 3.2.1 and Scala.3.2.2-RC1
With Scala 3.2.1, when the method jweEncrypt is invoked, it throws a java.lang.IllegalAccessError. With all versions prior to Scala 3.2.1, the method is able to be executed.
Java Version
Java 17
Compiler version
Scala 3.2.1, Scala 3.2.2-RC1
Minimized code
Change the scala3Version to 3.2.0 then run the test suite to see the expected output.
build.sbt
MySuite.scala
Output
Expectation
The text was updated successfully, but these errors were encountered: