-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Show an error message when the unicode escaped version of underscore is used as a local variable in a Java 21 project with preview disabled - Test error messages for underscore for Java 21 with and without preview enabled - Fix test failure related to resolving type of "var" variable in foreach loops Signed-off-by: David Thompson <davthomp@redhat.com>
- Loading branch information
Showing
8 changed files
with
182 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...er/src/org/eclipse/jdt/core/tests/compiler/regression/UseOfUnderscoreWithPreviewTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package org.eclipse.jdt.core.tests.compiler.regression; | ||
|
||
import java.util.Map; | ||
|
||
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; | ||
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; | ||
|
||
import junit.framework.Test; | ||
|
||
public class UseOfUnderscoreWithPreviewTest extends AbstractBatchCompilerTest { | ||
|
||
public static Test suite() { | ||
return buildMinimalComplianceTestSuite(UseOfUnderscoreWithPreviewTest.class, F_21); | ||
} | ||
|
||
public UseOfUnderscoreWithPreviewTest(String name) { | ||
super(name); | ||
} | ||
|
||
@Override | ||
protected Map<String, String> getCompilerOptions() { | ||
CompilerOptions compilerOptions = new CompilerOptions(super.getCompilerOptions()); | ||
if (compilerOptions.sourceLevel == ClassFileConstants.JDK21) { | ||
compilerOptions.enablePreviewFeatures = true; | ||
} | ||
return compilerOptions.getMap(); | ||
} | ||
|
||
public void testReportsUnderscoreInstanceMemberAsError() { | ||
String message = "As of release 21, '_' is only allowed to declare unnamed patterns, local variables, exception parameters or lambda parameters"; | ||
String errorLevel = "ERROR"; | ||
|
||
runNegativeTest(new String[] { "A.java", """ | ||
public class A { | ||
int _ = 1; | ||
public static void main(String[] args) { | ||
System.out.println("Hello, World!"); | ||
} | ||
} | ||
""" }, | ||
|
||
"----------\n" + | ||
"1. " + errorLevel + " in A.java (at line 2)\n" + | ||
" int _ = 1;\n" + | ||
" ^\n" + | ||
message + "\n" + | ||
"----------\n"); | ||
} | ||
|
||
public void testReportsUnicodeEscapeUnderscoreInstanceMemberAsError() { | ||
String message = "As of release 21, '_' is only allowed to declare unnamed patterns, local variables, exception parameters or lambda parameters"; | ||
String errorLevel = "ERROR"; | ||
|
||
runNegativeTest(new String[] { "A.java", """ | ||
public class A { | ||
int \\u005F = 1; | ||
public static void main(String[] args) { | ||
System.out.println("Hello, World!"); | ||
} | ||
} | ||
""" }, | ||
"----------\n" + | ||
"1. " + errorLevel + " in A.java (at line 2)\n" + | ||
" int \\u005F = 1;\n" + | ||
" ^^^^^^\n" + | ||
message + "\n" + | ||
"----------\n"); | ||
} | ||
|
||
public void testReportsUnderscoreParameterAsError() { | ||
String message = "As of release 21, '_' is only allowed to declare unnamed patterns, local variables, exception parameters or lambda parameters"; | ||
String errorLevel = "ERROR"; | ||
|
||
runNegativeTest(new String[] { "A.java", """ | ||
public class A { | ||
public static void main(String[] args) { | ||
foo(1); | ||
} | ||
public static void foo(int _) { | ||
System.out.println("Hello, World!"); | ||
} | ||
} | ||
""" }, | ||
"----------\n" + | ||
"1. " + errorLevel + " in A.java (at line 5)\n" + | ||
" public static void foo(int _) {\n" + | ||
" ^\n" + | ||
message + "\n" + | ||
"----------\n"); | ||
} | ||
|
||
public void testReportsUnderscoreParameterAsErrorUnicodeEscape() { | ||
String message = "As of release 21, '_' is only allowed to declare unnamed patterns, local variables, exception parameters or lambda parameters"; | ||
String errorLevel = "ERROR"; | ||
|
||
runNegativeTest(new String[] { "A.java", """ | ||
public class A { | ||
public static void main(String[] args) { | ||
foo(1); | ||
} | ||
public static void foo(int \\u005F) { | ||
System.out.println("Hello, World!"); | ||
} | ||
} | ||
""" }, | ||
"----------\n" + | ||
"1. " + errorLevel + " in A.java (at line 5)\n" + | ||
" public static void foo(int \\u005F) {\n" + | ||
" ^^^^^^\n" + | ||
message + "\n" + | ||
"----------\n"); | ||
} | ||
|
||
public void testReportsUnderscoreLocalVariableAsErrorUnicodeEscape() { | ||
runConformTest(new String[] { "A.java", | ||
""" | ||
public class A { | ||
public static void main(String[] args) { | ||
int \\u005F = 12; | ||
System.out.println("hello, world"); | ||
} | ||
} | ||
"""}, | ||
"hello, world", null, new String[] { "--enable-preview" }); | ||
} | ||
|
||
} |
Binary file not shown.