You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
src/scala/SomeClass.scala:3: error: type mismatch;
found : p.Z
required: q.Z
val z2: q.Z = p.UseIt.getZ //error here
^
one error found
This works when the return type in Java is fully qualified.
I think what's causing this is a difference in precedence/shadowing between Scala and Java. In Java, although UseIt is in package p and has access to p.Z, the import q.Z shadows it:
JLS 6.4.1:
{quote}A single-type-import declaration d in a compilation unit c of package p that imports a type named n shadows, throughout c, the declarations of:
any top level type named n declared in another compilation unit of p{quote}
In the SLS chapter 2, assuming a "compilation unit" includes all classes in a package regardless of which file they are in, the class p.Z has a higher precedence than the import q.Z. I assume that when the Scala compiler reads in Java and does the Scala conversion, it ends up mistakenly using the scoping rules from Scala instead of Java.
The text was updated successfully, but these errors were encountered:
@retronym said (edited on Apr 17, 2013 9:01:10 PM UTC):
Yep, same bug. Your project compiles with 2.10.2-SNAPSHOT. 2.10.2-RC1 is scheduled for for mid-May.
~/Downloads/ScalaJavaMix sbt -sbt-create -scala-version 2.10.1 compile
Detected sbt version 0.12.1
Using /Users/jason/.sbt/0.12.1 as sbt dir, -sbt-dir to override.
[info] Loading global plugins from /Users/jason/.sbt/0.12.1/plugins
[info] Set current project to default-c9f4e7 (in build file:/Users/jason/Downloads/ScalaJavaMix/)
[info] Defining *:scala-version
[info] The new value will be used by no settings or tasks.
[info] Reapplying settings...
[info] Set current project to default-c9f4e7 (in build file:/Users/jason/Downloads/ScalaJavaMix/)
[info] Updating {file:/Users/jason/Downloads/ScalaJavaMix/}default-c9f4e7...
[info] Resolving org.scala-lang#scala-library;2.10.1 ...
[info] Done updating.
[info] Compiling 1 Scala source and 4 Java sources to /Users/jason/Downloads/ScalaJavaMix/target/scala-2.10/classes...
[error] /Users/jason/Downloads/ScalaJavaMix/src/main/scala/my/test/bl/handler/BusinessHandler.scala:6: value getAssignedUsr is not a member of my.test.bl.bo.Drawer
[error] System.out.println(drw.getAssignedUsr())
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 2 s, completed Apr 17, 2013 10:58:49 PM
~/Downloads/ScalaJavaMix sbt -sbt-create -scala-home /code/scala2/build/pack compile
Detected sbt version 0.12.1
Using /Users/jason/.sbt/0.12.1 as sbt dir, -sbt-dir to override.
[info] Loading global plugins from /Users/jason/.sbt/0.12.1/plugins
[info] Set current project to default-c9f4e7 (in build file:/Users/jason/Downloads/ScalaJavaMix/)
[info] Defining {.}/*:scala-home
[info] The new value will be used by no settings or tasks.
[info] Reapplying settings...
[info] Set current project to default-c9f4e7 (in build file:/Users/jason/Downloads/ScalaJavaMix/)
[success] Total time: 0 s, completed Apr 17, 2013 10:59:04 PM
In Java, I have:
In Scala:
When compiling, there is an error:
This works when the return type in Java is fully qualified.
I think what's causing this is a difference in precedence/shadowing between Scala and Java. In Java, although
UseIt
is in packagep
and has access top.Z
, theimport q.Z
shadows it:JLS 6.4.1:
{quote}A single-type-import declaration d in a compilation unit c of package p that imports a type named n shadows, throughout c, the declarations of:
In the SLS chapter 2, assuming a "compilation unit" includes all classes in a package regardless of which file they are in, the class
p.Z
has a higher precedence than theimport q.Z
. I assume that when the Scala compiler reads in Java and does the Scala conversion, it ends up mistakenly using the scoping rules from Scala instead of Java.The text was updated successfully, but these errors were encountered: