8291914: generated constructors are considered compact when they shouldn't
Reviewed-by: darcy, jlahoda
This commit is contained in:
parent
9b971626f7
commit
95dd376ba2
@ -2302,7 +2302,8 @@ public class Flow {
|
||||
// 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;
|
||||
@ -2312,10 +2313,10 @@ public class Flow {
|
||||
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() &&
|
||||
|
@ -2770,7 +2770,8 @@ public class Lower extends TreeTranslator {
|
||||
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()) {
|
||||
|
@ -1417,7 +1417,7 @@ public class TypeEnter implements Completer {
|
||||
/* 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) {
|
||||
|
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8289249
|
||||
* @bug 8289249 8291914
|
||||
* @summary Test Elements.{isCompactConstructor, isCanonicalConstructor}
|
||||
* @library /tools/javac/lib
|
||||
* @build JavacTestingAbstractProcessor TestRecordPredicates
|
||||
@ -107,7 +107,7 @@ public class TestRecordPredicates extends JavacTestingAbstractProcessor {
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user