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
Erasure and inheritance collude: compiler attempts cast to an inaccessible class #4283
Comments
@axel22 said: |
@lindydonna said: |
@lindydonna said: |
@paulp said: // Ab.java
package test;
class Aa { public int t; }
public class Ab extends Aa { }
// a.scala
object Test extends App { (new test.Ab).t } |
@odersky said: |
@odersky said (edited by @lrytz on Mar 22, 2017 8:46:32 AM UTC): |
@dragos said (edited by @lrytz on Mar 22, 2017 8:46:48 AM UTC): |
@lrytz said (edited on Apr 11, 2016 8:36:12 AM UTC): A.java package a;
/*package private*/ abstract class A { public int t; } B.java package a;
public class B extends A { } Test.scala package b
object Test {
def main(args: Array[String]): Unit = {
val b = new a.B
b.t = 10
}
}
I'll push a fix. |
@lrytz said: |
A super access to a protected member in a package-protected class is allowed through an intermediate public class. The fix for scala/bug#5162 actually introduced an error for this case, because the scala compiler would generate an INVOKESPECIAL with the package-protected class as receiver, which is illegal. However, we can use the public intermediate class in the invocation signature. Fixes scala/bug#7936 This is very similar to scala/bug#4283
Because of erasure, the compiler needs to insert casts to get the expected type. The "expected type" logic seems to depend on the use of the type, rather than the statically-known type.
In this example, since the class
AbstractFoo
is the one that defines the fieldt
, the compiler thinks it needs to cast the result ofScalaBipp.make.get
toAbstractFoo
in order to accesst
. This is incorrect behavior, sinceAbstractFoo
might in fact be inaccessible in the scope in which the cast is applied.=== What steps will reproduce the problem (please be specific and use wikiformatting)? ===
test/AbstractFoo.java
ScalaBipp.scala
test.scala
=== What is the expected behavior? ===
No runtime failure.
=== What do you see instead? ===
Runtime exception accessing class
test.AbstractFoo
and the following bytecode:=== Additional information ===
The checkcast on line 13 is wrong. It should cast to
ScalaBipp
rather thanAbstractFoo
.test
=== Scala version ===
trunk r24156
The text was updated successfully, but these errors were encountered: