Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,7 @@ else if ((sym.owner.flags_field & INTERFACE) != 0)
if (allowValueClasses && (isInstanceFieldOfValueClass || isRecordField)) {
implicit |= FINAL | STRICT;
mask = ValueFieldFlags;
preview.checkSourceLevel(pos, Feature.VALUE_CLASSES);
} else {
mask = VarFlags;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ void test(Path baseDir, String className, String warningsGoldenFileName) throws
// compile
javaCompiler.compile(com.sun.tools.javac.util.List.of(javacFileManager.getJavaFileObject(javaFile)));
if (goldenFile != null) {
// lets remove preview related messages from the compilation output
compilationOutput.removeIf(msg -> msg.contains("compiler.note.preview"));
java.util.List<String> goldenFileContent = Files.readAllLines(goldenFile);
if (goldenFileContent.size() != compilationOutput.size()) {
System.err.println("compilation output length mismatch");
Expand Down
2 changes: 2 additions & 0 deletions test/langtools/tools/javac/SuperInit/SuperInitFails.out
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ SuperInitFails.java:55:32: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:85:18: compiler.err.ctor.calls.not.allowed.here
SuperInitFails.java:91:13: compiler.err.return.before.superclass.initialized
SuperInitFails.java:152:18: compiler.err.call.must.only.appear.in.ctor
- compiler.note.preview.filename: SuperInitFails.java, DEFAULT
- compiler.note.preview.recompile
42 errors
2 changes: 2 additions & 0 deletions test/langtools/tools/javac/patterns/DominationWithPP.out
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ Domination.java:193:18: compiler.err.pattern.dominated
Domination.java:202:18: compiler.err.pattern.dominated
Domination.java:211:18: compiler.err.pattern.dominated
Domination.java:228:18: compiler.err.pattern.dominated
- compiler.note.preview.filename: Domination.java, DEFAULT
- compiler.note.preview.recompile
13 errors
3 changes: 2 additions & 1 deletion test/langtools/tools/javac/preview/PreviewAutoSuppress.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public class Use {
List.of("- compiler.warn.preview.feature.use.classfile: Record.class, " + FEATURE_VERSION,
"Outer.java:3:5: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.records)",
"Outer.java:3:5: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.records)",
"3 warnings");
"Outer.java:3:18: compiler.warn.preview.feature.use.plural: (compiler.misc.feature.value.classes)",
"4 warnings");
if (!log.equals(expected))
throw new Exception("expected output not found" + log);
checkPreviewClassfile(classes.resolve("test").resolve("Outer.class"), true); //TODO: correct?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1483,4 +1483,37 @@ value class Test {
"aconst_null,putstatic,getstatic,astore_2,aload_0,aload_2,putfield,aload_0,aload_2," +
"putfield,aload_0,invokespecial,return");
}

@Test
void testIdentityRecordUsesPreview() throws Exception {
String source_withComponents =
"""
record IdentityRecord(int i) {}
""";
String source_noComponents =
"""
record IdentityRecord() {}
""";
String[] previousOptions = getCompileOptions();
try {
setCompileOptions("--enable-preview",
"-source", Integer.toString(Runtime.version().feature()),
"-Xlint:preview");
assertOKWithWarning("compiler.warn.preview.feature.use.plural", 1, source_withComponents);

File dir = assertOK(true, source_withComponents);
File classFile = new File(dir, "IdentityRecord.class");
Assert.check(classFile.exists(), "missing class file");
Assert.check(ClassFile.of().parse(classFile.toPath()).minorVersion() == ClassFile.PREVIEW_MINOR_VERSION,
"identity records should produce preview class files when compiled with preview enabled");

dir = assertOK(true, source_noComponents);
classFile = new File(dir, "IdentityRecord.class");
Assert.check(classFile.exists(), "missing class file");
Assert.check(ClassFile.of().parse(classFile.toPath()).minorVersion() == 0,
"identity records with no components should not produce preview class files even with preview enabled");
} finally {
setCompileOptions(previousOptions);
}
}
}