-
Notifications
You must be signed in to change notification settings - Fork 21
DelayedInit transformation needs more awareness of access restrictions #5565
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
Comments
Imported From: https://issues.scala-lang.org/browse/SI-5565?orig=1 |
@paulp said: This is probably fixed in trunk, but without a test case there's no way for me to say. |
@OlegYch said: D:\test\>javac pack2\*.java
D:\test\>d:\Distrib\Coding\Java\scala\scala-2.9.1.final\bin\scalac.bat pack2\*.java *.scala
test.scala:5: error: variable i in object base cannot be accessed in object pack2.base
Access to protected variable i not permitted because
enclosing class object test in package pack1 is not a subclass of
object base in package pack2 where target is defined
println(base.i)
^
one error found with nightly build: D:\test>d:\Distrib\Coding\Java\scala\scala-2.10.0-M2-0118-gf1c39dd981-2012-03-11\bin\scalac.bat pack2\*.java *.scala
D:\test>javac pack2\*.java
D:\test>d:\Distrib\Coding\Java\scala\scala-2.10.0-M2-0118-gf1c39dd981-2012-03-11\bin\scala.bat pack1.test
java.lang.IllegalAccessError: tried to access field pack2.base.i from class pack1.test$delayedInit$body
at pack1.test$delayedInit$body.apply(test.scala:5)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:61)
at scala.App$$anonfun$main$1.apply(App.scala:61)
at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
at scala.collection.immutable.List.foreach(List.scala:77)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:31)
at scala.App$class.main(App.scala:61)
at pack1.test$.main(test.scala:4)
at pack1.test.main(test.scala)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at scala.tools.nsc.util.ScalaClassLoader$$anonfun$run$1.apply(ScalaClassLoader.scala:90)
at scala.tools.nsc.util.ScalaClassLoader$class.asContext(ScalaClassLoader.scala:38)
at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.asContext(ScalaClassLoader.scala:159)
at scala.tools.nsc.util.ScalaClassLoader$class.run(ScalaClassLoader.scala:90)
at scala.tools.nsc.util.ScalaClassLoader$URLClassLoader.run(ScalaClassLoader.scala:159)
at scala.tools.nsc.CommonRunner$class.run(ObjectRunner.scala:28)
at scala.tools.nsc.ObjectRunner$.run(ObjectRunner.scala:45)
at scala.tools.nsc.CommonRunner$class.runAndCatch(ObjectRunner.scala:35)
at scala.tools.nsc.ObjectRunner$.runAndCatch(ObjectRunner.scala:45)
at scala.tools.nsc.MainGenericRunner.runTarget$1(MainGenericRunner.scala:70)
at scala.tools.nsc.MainGenericRunner.process(MainGenericRunner.scala:92)
at scala.tools.nsc.MainGenericRunner$.main(MainGenericRunner.scala:101)
at scala.tools.nsc.MainGenericRunner.main(MainGenericRunner.scala) |
@paulp said: object test extends base {
def main(args: Array[String]): Unit = {
println(base.i)
}
} |
@OlegYch said: |
@paulp said: |
@dwijnand said: object illegal_access_error_test_case extends App {
implicit def doubleWithApproxEquals(d: Double) = new {
def ~==(v: Double, margin: Double = 0.001): Boolean =
math.abs(d - v) < margin
}
assert(math.abs(-4.0) ~== (4.0, 0.001))
assert(math.abs(-4.0) ~== 4.0)
}
|
@adriaanm said: |
@magarciaEPFL said: in particular scala/scala@b4fbb7b |
@adriaanm said: |
@retronym said: Fixed in b4fbb7be0e by @magarcia |
This is related to #1806
First, i just spent an hour trying to workaround this issue, so I'd expect someone would really appreciate if protected statics were just treated as public.
Second, I got this error message:
"Access to protected variable staticReference not permitted because enclosing class object SpringWebApplication in package ui is not a subclass of object WebApplication in package navigator7 where target is defined var webApplication = if (WebApplication.staticReference == null) {"
here is the definition:
object SpringWebApplication extends WebApplication{ }
it really looks like it is a subclass, but the message tells me it is not.
Instead of this lengthy explanation, I would prefer to see some steps of how to work around the problem, e.g. "Use reflection or write a java wrapper to access this field, because scala does not allow accessing protected static members"
The text was updated successfully, but these errors were encountered: