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

Scala class inheriting a Java class and overriding method with inner class parameter #3120

Closed
scabug opened this Issue Feb 27, 2010 · 5 comments

Comments

Projects
None yet
2 participants
@scabug
Copy link

commented Feb 27, 2010

I have this Java class with inner class:

MyClassWithInner.java:

public class MyClassWithInner {
    public class MyInnerClass {}
}

Then another Java class using MyInnerClass:

MyBaseJavaClass.java:

public class MyBaseJavaClass {
    public void passInner(MyClassWithInner.MyInnerClass myInner) {}
}

Finally, this Scala class:

MyDerivedScalaClass.scala:

class MyDerivedScalaClass extends MyBaseJavaClass {
    override def passInner(myInner: MyClassWithInner#MyInnerClass) = {}
}

Compiling:

scalac scala/*.scala java/*.java

java/MyBaseJavaClass.java:2: error: not found: value MyClassWithInner
    public void passInner(MyClassWithInner.MyInnerClass myInner) {}

Same result with 2.7.7 and 2.8.0.Beta1.

See this discussion:

http://comments.gmane.org/gmane.comp.lang.scala.user/24133

@scabug

This comment has been minimized.

Copy link
Author

commented Feb 27, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3120?orig=1
Reporter: Erik Bruchez (ebruchez)

@scabug

This comment has been minimized.

Copy link
Author

commented Feb 27, 2010

@paulp said:
Sorry, I was going to open this, hadn't gotten to it. Here is the issue. Observe these classes:

public class J1 {
  public class Inner1 { }
  public static class Inner2 { }
}
public class J2 {
  public void f1(J1.Inner1 p) { }
  public void f2(J1.Inner2 p) { }
}
public class Q {
  public void passInner(J1.Inner1 myInner) {}
}

When scala parses the method signatures in J2, it treats them as member selections. In scala we write J1.Inner1 for the static version and J1#Inner1 for the instance, but java offers no such crutch. The reason I couldn't dash off an easy fix is that at the parsing stage it doesn't yet know which it is.

In JavaParsers I could do this:

- Select(qual, name.toTypeName)
+ SelectFromTypeTree(convertToTypeId(qual), name.toTypeName)

and in fact that fixes this bug, but then breaks anything that needed the guess to go the other way. So I will need some input on how to defer it long enough to obtain the type information.

@scabug

This comment has been minimized.

Copy link
Author

commented Mar 13, 2010

@odersky said:
There's nothing elegant we can do here. The only hack I see is to try first one and then the other when typechecking Java files. I'll try that.

@scabug

This comment has been minimized.

Copy link
Author

commented Mar 13, 2010

@odersky said:
(In 3ff77430de) Closes #3120. Review by extempore.

@scabug

This comment has been minimized.

Copy link
Author

commented Mar 14, 2010

Erik Bruchez (ebruchez) said:
Excellent, I tried this on the latest trunk and my example now compiles without errors!

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