Skip to content
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

Reflection exceptions using structural types with Java classes #11656

rjmac opened this issue Jul 31, 2019 · 0 comments


Copy link

commented Jul 31, 2019

Here is a case where the compiler accepts a structural type ascription and generates code which throws at runtime. It happens on at least 2.12.8 and 2.13.0:

package failure.otherpackage;

public class JavaClass {
    protected void foo() {
package failure.somepackage

import scala.language.reflectiveCalls
import failure.otherpackage._

object Main extends App {
  val j : { def foo(): Unit } = new JavaClass  // accepted by the compiler // throws an exception at runtime

This is probably related to #5352, which is ancient and closed. The associated fix (bedb33fd7cb) appears to have regressed. It seems the compiler treats all "non-private" access modifies as "public" when deciding whether a type matches a structural description.

@lrytz lrytz added this to the Backlog milestone Jul 31, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.