File tree Expand file tree Collapse file tree 4 files changed +9
-7
lines changed
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
test/langtools/tools/javac/processing/model/util/elements Expand file tree Collapse file tree 4 files changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -2302,7 +2302,8 @@ public void visitMethodDef(JCMethodDecl tree) {
23022302 // leave caught unchanged.
23032303 scan (tree .body );
23042304
2305- boolean isCompactConstructor = (tree .sym .flags () & Flags .COMPACT_RECORD_CONSTRUCTOR ) != 0 ;
2305+ boolean isCompactOrGeneratedRecordConstructor = (tree .sym .flags () & Flags .COMPACT_RECORD_CONSTRUCTOR ) != 0 ||
2306+ (tree .sym .flags () & (GENERATEDCONSTR | RECORD )) == (GENERATEDCONSTR | RECORD );
23062307 if (isInitialConstructor ) {
23072308 boolean isSynthesized = (tree .sym .flags () &
23082309 GENERATEDCONSTR ) != 0 ;
@@ -2312,10 +2313,10 @@ public void visitMethodDef(JCMethodDecl tree) {
23122313 if (var .owner == classDef .sym ) {
23132314 // choose the diagnostic position based on whether
23142315 // the ctor is default(synthesized) or not
2315- if (isSynthesized && !isCompactConstructor ) {
2316+ if (isSynthesized && !isCompactOrGeneratedRecordConstructor ) {
23162317 checkInit (TreeInfo .diagnosticPositionFor (var , vardecl ),
23172318 var , Errors .VarNotInitializedInDefaultConstructor (var ));
2318- } else if (isCompactConstructor ) {
2319+ } else if (isCompactOrGeneratedRecordConstructor ) {
23192320 boolean isInstanceRecordField = var .enclClass ().isRecord () &&
23202321 (var .flags_field & (Flags .PRIVATE | Flags .FINAL | Flags .GENERATED_MEMBER | Flags .RECORD )) != 0 &&
23212322 !var .isStatic () &&
Original file line number Diff line number Diff line change @@ -2770,7 +2770,8 @@ private void visitMethodDefInternal(JCMethodDecl tree) {
27702770 lambdaTranslationMap = prevLambdaTranslationMap ;
27712771 }
27722772 }
2773- if (tree .name == names .init && (tree .sym .flags_field & Flags .COMPACT_RECORD_CONSTRUCTOR ) != 0 ) {
2773+ if (tree .name == names .init && ((tree .sym .flags_field & Flags .COMPACT_RECORD_CONSTRUCTOR ) != 0 ||
2774+ (tree .sym .flags_field & (GENERATEDCONSTR | RECORD )) == (GENERATEDCONSTR | RECORD ))) {
27742775 // lets find out if there is any field waiting to be initialized
27752776 ListBuffer <VarSymbol > fields = new ListBuffer <>();
27762777 for (Symbol sym : currentClass .getEnclosedElements ()) {
Original file line number Diff line number Diff line change @@ -1417,7 +1417,7 @@ public MethodSymbol constructorSymbol() {
14171417 /* if we have to generate a default constructor for records we will treat it as the compact one
14181418 * to trigger field initialization later on
14191419 */
1420- csym .flags_field |= Flags . COMPACT_RECORD_CONSTRUCTOR | GENERATEDCONSTR ;
1420+ csym .flags_field |= GENERATEDCONSTR ;
14211421 ListBuffer <VarSymbol > params = new ListBuffer <>();
14221422 JCVariableDecl lastField = recordFieldDecls .last ();
14231423 for (JCVariableDecl field : recordFieldDecls ) {
Original file line number Diff line number Diff line change 2323
2424/*
2525 * @test
26- * @bug 8289249
26+ * @bug 8289249 8291914
2727 * @summary Test Elements.{isCompactConstructor, isCanonicalConstructor}
2828 * @library /tools/javac/lib
2929 * @build JavacTestingAbstractProcessor TestRecordPredicates
@@ -107,7 +107,7 @@ private void expectFalse(java.util.function.BooleanSupplier bs) {
107107 boolean isCanonical () default false ;
108108 }
109109
110- @ ExpectedPredicates (isCompact =true , isCanonical =true )
110+ @ ExpectedPredicates (isCompact =false , isCanonical =true )
111111 record RecordCompactCtor (int foo , double bar ) {}
112112
113113 // Example from JLS 8.10.4.2
You can’t perform that action at this time.
0 commit comments