Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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 @@ -2302,7 +2302,8 @@ public void visitMethodDef(JCMethodDecl tree) {
// leave caught unchanged.
scan(tree.body);

boolean isCompactConstructor = (tree.sym.flags() & Flags.COMPACT_RECORD_CONSTRUCTOR) != 0;
boolean isCompactOrGeneratedRecordConstructor = (tree.sym.flags() & Flags.COMPACT_RECORD_CONSTRUCTOR) != 0 ||
(tree.sym.flags() & (GENERATEDCONSTR | RECORD)) == (GENERATEDCONSTR | RECORD);
if (isInitialConstructor) {
boolean isSynthesized = (tree.sym.flags() &
GENERATEDCONSTR) != 0;
Expand All @@ -2312,10 +2313,10 @@ public void visitMethodDef(JCMethodDecl tree) {
if (var.owner == classDef.sym) {
// choose the diagnostic position based on whether
// the ctor is default(synthesized) or not
if (isSynthesized && !isCompactConstructor) {
if (isSynthesized && !isCompactOrGeneratedRecordConstructor) {
checkInit(TreeInfo.diagnosticPositionFor(var, vardecl),
var, Errors.VarNotInitializedInDefaultConstructor(var));
} else if (isCompactConstructor) {
} else if (isCompactOrGeneratedRecordConstructor) {
boolean isInstanceRecordField = var.enclClass().isRecord() &&
(var.flags_field & (Flags.PRIVATE | Flags.FINAL | Flags.GENERATED_MEMBER | Flags.RECORD)) != 0 &&
!var.isStatic() &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2770,7 +2770,8 @@ private void visitMethodDefInternal(JCMethodDecl tree) {
lambdaTranslationMap = prevLambdaTranslationMap;
}
}
if (tree.name == names.init && (tree.sym.flags_field & Flags.COMPACT_RECORD_CONSTRUCTOR) != 0) {
if (tree.name == names.init && ((tree.sym.flags_field & Flags.COMPACT_RECORD_CONSTRUCTOR) != 0 ||
(tree.sym.flags_field & (GENERATEDCONSTR | RECORD)) == (GENERATEDCONSTR | RECORD))) {
// lets find out if there is any field waiting to be initialized
ListBuffer<VarSymbol> fields = new ListBuffer<>();
for (Symbol sym : currentClass.getEnclosedElements()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ public MethodSymbol constructorSymbol() {
/* if we have to generate a default constructor for records we will treat it as the compact one
* to trigger field initialization later on
*/
csym.flags_field |= Flags.COMPACT_RECORD_CONSTRUCTOR | GENERATEDCONSTR;
csym.flags_field |= GENERATEDCONSTR;
ListBuffer<VarSymbol> params = new ListBuffer<>();
JCVariableDecl lastField = recordFieldDecls.last();
for (JCVariableDecl field : recordFieldDecls) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 8289249
* @bug 8289249 8291914
* @summary Test Elements.{isCompactConstructor, isCanonicalConstructor}
* @library /tools/javac/lib
* @build JavacTestingAbstractProcessor TestRecordPredicates
Expand Down Expand Up @@ -107,7 +107,7 @@ private void expectFalse(java.util.function.BooleanSupplier bs) {
boolean isCanonical() default false;
}

@ExpectedPredicates(isCompact=true, isCanonical=true)
@ExpectedPredicates(isCompact=false, isCanonical=true)
record RecordCompactCtor(int foo, double bar) {}

// Example from JLS 8.10.4.2
Expand Down