Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManoj Palat2020-09-08 01:25:07 +0000
committerManoj Palat2020-09-08 04:44:09 +0000
commit3c343450ffbb83881ddacf6ce5b72482ef9a4684 (patch)
tree733663ebe87fc1e6808eb5f97ad75faeff4b0848
parent9c56002a7c3353a731cf08eb1cc844d7852d5c2d (diff)
downloadeclipse.jdt.core-3c343450ffbb83881ddacf6ce5b72482ef9a4684.tar.gz
eclipse.jdt.core-3c343450ffbb83881ddacf6ce5b72482ef9a4684.tar.xz
eclipse.jdt.core-3c343450ffbb83881ddacf6ce5b72482ef9a4684.zip
Bug 566748 - incorrect error message for accessing non-static vars from
static context of local interface Change-Id: Ibe81cbdf5730d599ccb8188459dd23e211d13f63 Signed-off-by: Manoj Palat <manpalat@in.ibm.com>
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest_15.java79
-rw-r--r--org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java2
-rw-r--r--org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties2
3 files changed, 79 insertions, 4 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest_15.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest_15.java
index 5fe0f5f8e2..8f7f1f1d71 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest_15.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LocalStaticsTest_15.java
@@ -208,7 +208,7 @@ public class LocalStaticsTest_15 extends AbstractRegressionTest {
"1. ERROR in X.java (at line 12)\n" +
" System.out.println(li); // error, local variable of method of outer enclosing class\n" +
" ^^\n" +
- "Cannot make a static reference to the non-static variable li from a local record\n" +
+ "Cannot make a static reference to the non-static variable li\n" +
"----------\n" +
"2. ERROR in X.java (at line 13)\n" +
" System.out.println(nsi); // error, non-static member\n" +
@@ -218,7 +218,7 @@ public class LocalStaticsTest_15 extends AbstractRegressionTest {
"3. ERROR in X.java (at line 26)\n" +
" I myI = s -> li; // error - local var of outer class\n" +
" ^^\n" +
- "Cannot make a static reference to the non-static variable li from a local record\n" +
+ "Cannot make a static reference to the non-static variable li\n" +
"----------\n"
);
}
@@ -566,4 +566,79 @@ public class LocalStaticsTest_15 extends AbstractRegressionTest {
"----------\n"
);
}
+ public void testBug566748_001() {
+ runNegativeTest(
+ new String[] {
+ "X.java",
+ "class X<T> {\n"+
+ " int count;\n"+
+ " void doNothing() {}\n"+
+ " void foo1(String s) {\n"+
+ " int i;\n"+
+ " interface I {\n"+
+ " default X<T> bar() {\n"+
+ " if (count > 0 || i > 0 || s == null)\n"+
+ " return null;\n"+
+ " doNothing();\n"+
+ " return null;\n"+
+ " }\n"+
+ " } \n"+
+ " }\n"+
+ " void foo2(String s) {\n"+
+ " try {\n"+
+ " throw new Exception();\n"+
+ " } catch (Exception e) {\n"+
+ " interface I {\n"+
+ " default int bar() {\n"+
+ " return e != null ? 0 : 1;\n"+
+ " }\n"+
+ " } \n"+
+ " \n"+
+ " }\n"+
+ " }\n"+
+ "}"
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 6)\n" +
+ " interface I {\n" +
+ " ^\n" +
+ "The type I is never used locally\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " default X<T> bar() {\n" +
+ " ^\n" +
+ "Cannot make a static reference to the non-static type T\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 8)\n" +
+ " if (count > 0 || i > 0 || s == null)\n" +
+ " ^^^^^\n" +
+ "Cannot make a static reference to the non-static field count\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 8)\n" +
+ " if (count > 0 || i > 0 || s == null)\n" +
+ " ^\n" +
+ "Cannot make a static reference to the non-static variable i\n" +
+ "----------\n" +
+ "5. ERROR in X.java (at line 8)\n" +
+ " if (count > 0 || i > 0 || s == null)\n" +
+ " ^\n" +
+ "Cannot make a static reference to the non-static variable s\n" +
+ "----------\n" +
+ "6. ERROR in X.java (at line 10)\n" +
+ " doNothing();\n" +
+ " ^^^^^^^^^\n" +
+ "Cannot make a static reference to the non-static method doNothing() from the type X<T>\n" +
+ "----------\n" +
+ "7. WARNING in X.java (at line 19)\n" +
+ " interface I {\n" +
+ " ^\n" +
+ "The type I is never used locally\n" +
+ "----------\n" +
+ "8. ERROR in X.java (at line 21)\n" +
+ " return e != null ? 0 : 1;\n" +
+ " ^\n" +
+ "Cannot make a static reference to the non-static variable e\n" +
+ "----------\n"
+ );
+ }
} \ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
index d91c9ef6b8..0a19b63517 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordsRestrictedClassTest.java
@@ -2361,7 +2361,7 @@ public void testBug560893_007() {
"1. ERROR in X.java (at line 10)\n" +
" System.out.println(li); // error, local variable\n" +
" ^^\n" +
- "Cannot make a static reference to the non-static variable li from a local record\n" +
+ "Cannot make a static reference to the non-static variable li\n" +
"----------\n" +
"2. ERROR in X.java (at line 11)\n" +
" System.out.println(nsi); // error, non-static member\n" +
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
index 57bd4933e3..439ecb7358 100644
--- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
+++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/messages.properties
@@ -1053,7 +1053,7 @@
1752 = The type {1} may not subclass {0} explicitly
1753 = void is an invalid type for the component {0} of a record
1754 = The variable argument type {0} of the record {1} must be the last parameter
-1755 = Cannot make a static reference to the non-static variable {0} from a local record
+1755 = Cannot make a static reference to the non-static variable {0}
1756 = A record declaration {0} is not allowed in a local inner class
1757 = A record component {0} cannot have modifiers
1758 = Illegal parameter name {0} in canonical constructor, expected {1}, the corresponding component name

Back to the top