@@ -28,7 +28,7 @@ public class PreviewFlagTest extends AbstractRegressionTest9 {
2828 static {
2929// TESTS_NUMBERS = new int [] { 1 };
3030// TESTS_RANGE = new int[] { 1, -1 };
31- // TESTS_NAMES = new String[] { "testIssue3614_001 " };
31+ // TESTS_NAMES = new String[] { "testIssue3943_001 " };
3232// TESTS_NAMES = new String[] { "testIssue3614_001" };
3333 }
3434 private String extraLibPath ;
@@ -151,15 +151,21 @@ public static void main(String[] args) {
151151 ScopedValue<Integer> si = ScopedValue.newInstance();
152152 System.out.println(si == null ? "hello" : "world");
153153 }
154+ public int foo() {}
154155 }
155156 """
156157 },
157- "----------\n " +
158- "1. ERROR in X.java (at line 3)\n " +
159- " ScopedValue<Integer> si = ScopedValue.newInstance();\n " +
160- " ^^^^^^^^^^^\n " +
161- "This API is part of the preview feature 'Scoped Values' which is disabled by default. Use --enable-preview to enable\n " +
162- "----------\n " ,
158+ "----------\n " +
159+ "1. ERROR in X.java (at line 3)\n " +
160+ " ScopedValue<Integer> si = ScopedValue.newInstance();\n " +
161+ " ^^^^^^^^^^^\n " +
162+ "This API is part of the preview feature 'Scoped Values' which is disabled by default. Use --enable-preview to enable\n " +
163+ "----------\n " +
164+ "2. ERROR in X.java (at line 6)\n " +
165+ " public int foo() {}\n " +
166+ " ^^^^^\n " +
167+ "This method must return a result of type int\n " +
168+ "----------\n " ,
163169 null ,
164170 true ,
165171 options );
@@ -181,12 +187,12 @@ public static void main(String... args) {}
181187 """
182188 };
183189 runner .expectedCompilerLog =
184- "----------\n " +
185- "1. WARNING in X.java (at line 4)\n " +
186- " return tree.isModule();\n " +
187- " ^^^^^^^^^^^^^^^\n " +
188- "This API is part of the preview feature 'Module Import Declarations' which is disabled by default. Use --enable-preview to enable\n " +
189- "----------\n " ;
190+ "----------\n " +
191+ "1. WARNING in X.java (at line 4)\n " +
192+ " return tree.isModule();\n " +
193+ " ^^^^^^^^^^^^^^^\n " +
194+ "This API is part of the preview feature 'Module Import Declarations' which is disabled by default. Use --enable-preview to enable\n " +
195+ "----------\n " ;
190196 runner .runConformTest ();
191197 }
192198 public void testIssue3614_003_enabled () throws Exception {
@@ -220,22 +226,68 @@ public void main(String... args) {
220226 }
221227 public void testIssue3943_001 () throws IOException , ClassFormatException {
222228 Map <String , String > options = getCompilerOptions ();
223- String str = options .get (CompilerOptions .OPTION_EnablePreviews );
224- options .put (CompilerOptions .OPTION_Compliance , CompilerOptions .VERSION_24 );
225- options .put (CompilerOptions .OPTION_Source , CompilerOptions .VERSION_24 );
226- options .put (CompilerOptions .OPTION_TargetPlatform , CompilerOptions .VERSION_24 );
229+ String str = options .get (CompilerOptions .OPTION_Compliance );
230+ options .put (CompilerOptions .OPTION_Compliance , CompilerOptions .VERSION_23 );
231+ options .put (CompilerOptions .OPTION_Source , CompilerOptions .VERSION_23 );
232+ options .put (CompilerOptions .OPTION_TargetPlatform , CompilerOptions .VERSION_23 );
233+ options .put (CompilerOptions .OPTION_EnablePreviews , CompilerOptions .DISABLED );
234+ runNegativeTest (new String [] {
235+ "X.java" ,
236+ """
237+ public class X {
238+ public static void main(String[] args) {
239+ ScopedValue<Integer> si = ScopedValue.newInstance();
240+ System.out.println(si == null ? "hello" : "world");
241+ }
242+ public int foo() {}
243+ }
244+ """ },
245+ "----------\n " +
246+ "1. WARNING in X.java (at line 3)\n " +
247+ " ScopedValue<Integer> si = ScopedValue.newInstance();\n " +
248+ " ^^^^^^^^^^^\n " +
249+ "You are using an API that is part of the preview feature \' Scoped Values\' and may be removed in future\n " +
250+ "----------\n " +
251+ "2. ERROR in X.java (at line 6)\n " +
252+ " public int foo() {}\n " +
253+ " ^^^^^\n " +
254+ "This method must return a result of type int\n " +
255+ "----------\n " ,
256+ null ,
257+ true ,
258+ options );
259+ options .put (CompilerOptions .OPTION_Compliance , str );
260+ options .put (CompilerOptions .OPTION_Source , str );
261+ options .put (CompilerOptions .OPTION_TargetPlatform , str );
262+ options .put (CompilerOptions .OPTION_EnablePreviews , CompilerOptions .ENABLED );
263+ }
264+ public void testIssue3943_002 () throws IOException , ClassFormatException {
265+ Map <String , String > options = getCompilerOptions ();
266+ String str = options .get (CompilerOptions .OPTION_Compliance );
267+ options .put (CompilerOptions .OPTION_Compliance , CompilerOptions .VERSION_23 );
268+ options .put (CompilerOptions .OPTION_Source , CompilerOptions .VERSION_23 );
269+ options .put (CompilerOptions .OPTION_TargetPlatform , CompilerOptions .VERSION_23 );
227270 options .put (CompilerOptions .OPTION_EnablePreviews , CompilerOptions .DISABLED );
228- runConformTest (new String [] {
271+ runNegativeTest (new String [] {
229272 "X.java" ,
230273 """
231274 public class X {
275+ @SuppressWarnings("preview")
232276 public static void main(String[] args) {
233277 ScopedValue<Integer> si = ScopedValue.newInstance();
234278 System.out.println(si == null ? "hello" : "world");
235279 }
280+ public int foo() {}
236281 }
237282 """ },
238- "world" ,
283+ "----------\n " +
284+ "1. ERROR in X.java (at line 7)\n " +
285+ " public int foo() {}\n " +
286+ " ^^^^^\n " +
287+ "This method must return a result of type int\n " +
288+ "----------\n " ,
289+ null ,
290+ true ,
239291 options );
240292 options .put (CompilerOptions .OPTION_Compliance , str );
241293 options .put (CompilerOptions .OPTION_Source , str );
0 commit comments