From 7d03dcc45ff3b892bc5db8c9f334697c103e767a Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Sat, 16 Mar 2013 16:26:32 +0100 Subject: SI-7259 Fix detection of Java defined Selects The fix for SI-3120, 3ff7743, introduced a fallback within `typedSelect` that accounted for the ambiguity of a Java selection syntax. Does `A.B` refer to a member of the type `A` or of the companion object `A`? (The companion object here is a fiction used by scalac to group the static members of a Java class.) The fallback in `typedSelect` was predicated on `context.owner.enclosingTopLevelClass.isJavaDefined`. However, this was incorrectly including Select-s in top-level annotations in Scala files, which are owned by the enclosing package class, which is considered to be Java defined. This led to nonsensical error messages ("type scala not found.") Instead, this commit checks the compilation unit of the context, which is more direct and correct. (As I learned recently, `currentUnit.isJavaDefined` would *not* be correct, as a lazy type might complete a Java signature while compiling some other compilation unit!) A bonus post factum test case is included for SI-3120. Manual forward port of f046853 which was not merged as part of the routine 2.10.x to master merge. The test case uncovered a NullPointerExceptiion crasher in annotation typechecking introduced in 5878099c; this has been prevented with a null check. Conflicts: src/compiler/scala/tools/nsc/typechecker/Typers.scala --- test/files/pos/t3120/J1.java | 4 ++++ test/files/pos/t3120/J2.java | 4 ++++ test/files/pos/t3120/Q.java | 3 +++ test/files/pos/t3120/Test.scala | 3 +++ 4 files changed, 14 insertions(+) create mode 100644 test/files/pos/t3120/J1.java create mode 100644 test/files/pos/t3120/J2.java create mode 100644 test/files/pos/t3120/Q.java create mode 100644 test/files/pos/t3120/Test.scala (limited to 'test/files/pos') diff --git a/test/files/pos/t3120/J1.java b/test/files/pos/t3120/J1.java new file mode 100644 index 0000000000..12b23c1c98 --- /dev/null +++ b/test/files/pos/t3120/J1.java @@ -0,0 +1,4 @@ +class J1 { + public class Inner1 { } + public static class Inner2 { } +} diff --git a/test/files/pos/t3120/J2.java b/test/files/pos/t3120/J2.java new file mode 100644 index 0000000000..db6e859020 --- /dev/null +++ b/test/files/pos/t3120/J2.java @@ -0,0 +1,4 @@ +public class J2 { + public void f1(J1.Inner1 p) { } + public void f2(J1.Inner2 p) { } +} diff --git a/test/files/pos/t3120/Q.java b/test/files/pos/t3120/Q.java new file mode 100644 index 0000000000..fe2269308a --- /dev/null +++ b/test/files/pos/t3120/Q.java @@ -0,0 +1,3 @@ +public class Q { + public static void passInner(J1.Inner1 myInner) {} +} diff --git a/test/files/pos/t3120/Test.scala b/test/files/pos/t3120/Test.scala new file mode 100644 index 0000000000..c02146fba1 --- /dev/null +++ b/test/files/pos/t3120/Test.scala @@ -0,0 +1,3 @@ +object Test { + Q.passInner(null) +} -- cgit v1.2.3