diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java index cc0e5c38e58..4f7714c0fdb 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java @@ -124,6 +124,7 @@ public class Attr extends JCTree.Visitor { final ArgumentAttr argumentAttr; final MatchBindingsComputer matchBindingsComputer; final AttrRecover attrRecover; + final LocalProxyVarsGen localProxyVarsGen; public static Attr instance(Context context) { Attr instance = context.get(attrKey); @@ -163,6 +164,7 @@ protected Attr(Context context) { argumentAttr = ArgumentAttr.instance(context); matchBindingsComputer = MatchBindingsComputer.instance(context); attrRecover = AttrRecover.instance(context); + localProxyVarsGen = LocalProxyVarsGen.instance(context); Options options = Options.instance(context); @@ -317,7 +319,7 @@ void checkAssignable(DiagnosticPosition pos, VarSymbol v, JCTree base, Env handler) { - forEachInitializer(classDef, isStatic, false, handler); + forEachInitializer(classDef, isStatic, InitializerDisc.PROCESS_ALL, handler); + } + + enum InitializerDisc { + PROCESS_ALL, + EARLY_ONLY, + LATE_ONLY } /* Do something with static or non-static field initializers and initialization blocks. - * the `earlyOnly` argument will determine if we will deal or not with early variable instance + * the `discriminator` argument will determine if we will deal or not with early variable instance * initializers we want to process only those before a super() invocation and ignore them after * it. */ - protected void forEachInitializer(JCClassDecl classDef, boolean isStatic, boolean earlyOnly, + protected void forEachInitializer(JCClassDecl classDef, boolean isStatic, InitializerDisc discriminator, Consumer handler) { if (classDef == initScanClass) // avoid infinite loops return; @@ -515,15 +521,18 @@ protected void forEachInitializer(JCClassDecl classDef, boolean isStatic, boolea */ boolean isDefStatic = ((TreeInfo.flags(def) | (TreeInfo.symbolFor(def) == null ? 0 : TreeInfo.symbolFor(def).flags_field)) & STATIC) != 0; if (!def.hasTag(METHODDEF) && (isDefStatic == isStatic)) { - if (def instanceof JCVariableDecl varDecl) { - boolean isEarly = varDecl.init != null && - varDecl.sym.isStrict() && - !varDecl.sym.isStatic(); - if (isEarly == earlyOnly) { + if (discriminator == InitializerDisc.PROCESS_ALL) { + handler.accept(def); + } else { + if (def instanceof JCVariableDecl varDecl) { + boolean isEarly = varDecl.init != null && + !varDecl.sym.isStatic(); + if (isEarly && discriminator == InitializerDisc.EARLY_ONLY) { + handler.accept(def); + } + } else if (discriminator == InitializerDisc.LATE_ONLY) { handler.accept(def); } - } else if (!earlyOnly) { - handler.accept(def); } } } @@ -2221,13 +2230,17 @@ protected boolean trackable(VarSymbol sym) { return sym.pos >= startPos && ((sym.owner.kind == MTH || sym.owner.kind == VAR || - isFinalOrStrictUninitializedField(sym))); + isTrackableField(sym))); } - boolean isFinalOrStrictUninitializedField(VarSymbol sym) { + /* we want to track fields that are: + * - final regardless of "staticness" + * - non-final instance fields that lack an initializer + */ + boolean isTrackableField(VarSymbol sym) { return sym.owner.kind == TYP && (((sym.flags() & (FINAL | HASINIT | PARAMETER)) == FINAL || - (sym.flags() & (STRICT | HASINIT | PARAMETER)) == STRICT) && + (sym.flags() & (STRICT | HASINIT | PARAMETER)) == STRICT) && classDef.sym.isEnclosedBy((ClassSymbol)sym.owner)); } @@ -2560,15 +2573,18 @@ public void visitMethodDef(JCMethodDecl tree) { scan(tree.body); if (isConstructor) { - boolean isSynthesized = (tree.sym.flags() & - GENERATEDCONSTR) != 0; + boolean isAGeneratedConstructor = (tree.sym.flags() & GENERATEDCONSTR) != 0; for (int i = firstadr; i < nextadr; i++) { JCVariableDecl vardecl = vardecls[i]; VarSymbol var = vardecl.sym; if (var.owner == classDef.sym && !var.isStatic()) { + // ignore non-final instance fields + if (allowValueClasses && var.owner.kind == TYP && !var.isFinal()) { + continue; + } // choose the diagnostic position based on whether - // the ctor is default(synthesized) or not - if (isSynthesized && !isCompactOrGeneratedRecordConstructor) { + // the ctor is default(generated) or not + if (isAGeneratedConstructor && !isCompactOrGeneratedRecordConstructor) { checkInit(TreeInfo.diagnosticPositionFor(var, vardecl), var, Errors.VarNotInitializedInDefaultConstructor(var)); } else if (isCompactOrGeneratedRecordConstructor) { @@ -3086,7 +3102,7 @@ public void visitApply(JCMethodInvocation tree) { Name name = TreeInfo.name(tree.meth); // let's process early initializers if (name == names._super) { - forEachInitializer(classDef, false, true, def -> { + forEachInitializer(classDef, false, InitializerDisc.EARLY_ONLY, def -> { scan(def); clearPendingExits(false); }); @@ -3108,7 +3124,7 @@ public void visitApply(JCMethodInvocation tree) { checkInit(TreeInfo.diagEndPos(tree), var, Errors.StrictFieldNotHaveBeenInitializedBeforeSuper(var)); } } - forEachInitializer(classDef, false, def -> { + forEachInitializer(classDef, false, InitializerDisc.LATE_ONLY, def -> { scan(def); clearPendingExits(false); }); @@ -3118,7 +3134,7 @@ public void visitApply(JCMethodInvocation tree) { else if (name == names._this) { for (int address = firstadr; address < nextadr; address++) { VarSymbol sym = vardecls[address].sym; - if (isFinalOrStrictUninitializedField(sym) && !sym.isStatic()) + if (isTrackableField(sym) && !sym.isStatic()) letInit(tree.pos(), sym); } } @@ -3199,9 +3215,10 @@ public void visitAssign(JCAssign tree) { // assigned before reading their value public void visitSelect(JCFieldAccess tree) { super.visitSelect(tree); - if (TreeInfo.isThisQualifier(tree.selected) && - tree.sym.kind == VAR) { - checkInit(tree.pos(), (VarSymbol)tree.sym); + if (TreeInfo.isThisQualifier(tree.selected) && tree.sym.kind == VAR) { + if (trackable((VarSymbol)tree.sym)) { + checkInit(tree.pos(), (VarSymbol) tree.sym); + } } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LocalProxyVarsGen.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LocalProxyVarsGen.java index dea2dbfaf66..8a7846477a7 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LocalProxyVarsGen.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/LocalProxyVarsGen.java @@ -29,8 +29,10 @@ import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; +import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; import com.sun.tools.javac.code.Symbol; import com.sun.tools.javac.code.Symbol.ClassSymbol; @@ -88,8 +90,8 @@ public static LocalProxyVarsGen instance(Context context) { private TreeMaker make; private final UnsetFieldsInfo unsetFieldsInfo; private ClassSymbol currentClass = null; - private java.util.List strictInstanceFields; - private Map> strictFieldsReadInPrologue = new HashMap<>(); + private java.util.List instanceFields; + private Map> ASTsReferencedInPrologue = new HashMap<>(); private final boolean noLocalProxyVars; @@ -105,10 +107,27 @@ protected LocalProxyVarsGen(Context context) { noLocalProxyVars = options.isSet("noLocalProxyVars"); } - public void addStrictFieldReadInPrologue(JCMethodDecl constructor, Symbol sym) { - Set fieldSet = strictFieldsReadInPrologue.getOrDefault(constructor, new HashSet<>()); - fieldSet.add(sym); - strictFieldsReadInPrologue.put(constructor, fieldSet); + public void addASTReadInPrologue(JCMethodDecl constructor, JCTree tree) { + // better to have order for this one + Set treeSet = ASTsReferencedInPrologue.getOrDefault(constructor, new LinkedHashSet<>()); + treeSet.add(tree); + ASTsReferencedInPrologue.put(constructor, treeSet); + } + + public boolean removeASTReadInPrologue(JCMethodDecl constructor, JCTree tree) { + Set treeSet = ASTsReferencedInPrologue.get(constructor); + if (treeSet != null) { + return treeSet.remove(tree); + } + return false; + } + + public boolean hasAST(JCMethodDecl constructor, JCTree tree) { + Set treeSet = ASTsReferencedInPrologue.get(constructor); + if (treeSet != null) { + return treeSet.contains(tree); + } + return false; } public JCTree translateTopLevelClass(JCTree cdef, TreeMaker make) { @@ -128,32 +147,33 @@ public JCTree translateTopLevelClass(JCTree cdef, TreeMaker make) { @Override public void visitClassDef(JCClassDecl tree) { ClassSymbol prevCurrentClass = currentClass; - java.util.List prevStrictInstanceFields = strictInstanceFields; + java.util.List instanceFieldsPrev = instanceFields; try { currentClass = tree.sym; - strictInstanceFields = tree.defs.stream() + instanceFields = tree.defs.stream() .filter(t -> t.hasTag(VARDEF)) .map(t -> (JCVariableDecl)t) - .filter(vd -> vd.sym.isStrict() && !vd.sym.isStatic()) + .filter(vd -> !vd.sym.isStatic()) .collect(List.collector()); super.visitClassDef(tree); } finally { currentClass = prevCurrentClass; - strictInstanceFields = prevStrictInstanceFields; + instanceFields = instanceFieldsPrev; } } public void visitMethodDef(JCMethodDecl tree) { - if (strictFieldsReadInPrologue.get(tree) != null) { - Set fieldSet = strictFieldsReadInPrologue.get(tree); + if (ASTsReferencedInPrologue.get(tree) != null) { + Set ASTSet = ASTsReferencedInPrologue.get(tree); java.util.List strictFieldsRead = new ArrayList<>(); - for (JCVariableDecl sfield : strictInstanceFields) { - if (fieldSet.contains(sfield.sym)) { + Set symbols = ASTSet.stream().map(t -> TreeInfo.symbolFor(t)).collect(Collectors.toSet()); + for (JCVariableDecl sfield : instanceFields) { + if (symbols.contains(sfield.sym)) { strictFieldsRead.add(sfield); } } addLocalProxiesFor(tree, strictFieldsRead); - strictFieldsReadInPrologue.remove(tree); + ASTsReferencedInPrologue.remove(tree); } super.visitMethodDef(tree); } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java index ad7a66ae7ee..70a6a89f9ec 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java @@ -106,6 +106,7 @@ public class Resolve { ModuleFinder moduleFinder; Types types; JCDiagnostic.Factory diags; + private final LocalProxyVarsGen localProxyVarsGen; public final boolean allowModules; public final boolean allowRecords; private final boolean compactMethodDiags; @@ -115,7 +116,7 @@ public class Resolve { final EnumSet verboseResolutionMode; final boolean dumpMethodReferenceSearchResults; final boolean dumpStacktraceOnError; - private final LocalProxyVarsGen localProxyVarsGen; + private final boolean allowValueClasses; WriteableScope polymorphicSignatureScope; @@ -141,6 +142,7 @@ protected Resolve(Context context) { types = Types.instance(context); diags = JCDiagnostic.Factory.instance(context); preview = Preview.instance(context); + localProxyVarsGen = LocalProxyVarsGen.instance(context); Source source = Source.instance(context); Options options = Options.instance(context); compactMethodDiags = options.isSet(Option.XDIAGS, "compact") || @@ -155,7 +157,8 @@ protected Resolve(Context context) { allowRecords = Feature.RECORDS.allowedInSource(source); dumpMethodReferenceSearchResults = options.isSet("debug.dumpMethodReferenceSearchResults"); dumpStacktraceOnError = options.isSet("dev") || options.isSet(DOE); - localProxyVarsGen = LocalProxyVarsGen.instance(context); + allowValueClasses = (!preview.isPreview(Feature.VALUE_CLASSES) || preview.isEnabled()) && + Feature.VALUE_CLASSES.allowedInSource(source); } /** error symbols, which are returned when resolution fails @@ -1537,14 +1540,27 @@ Symbol findVar(DiagnosticPosition pos, Env env, Name name) { (sym.flags() & STATIC) == 0) { if (staticOnly) return new StaticError(sym); - if (env1.info.ctorPrologue && !isAllowedEarlyReference(pos, env1, (VarSymbol)sym)) { - if (!env.tree.hasTag(ASSIGN) || !TreeInfo.isIdentOrThisDotIdent(((JCAssign)env.tree).lhs)) { - if (!sym.isStrictInstance()) { + if (env1.info.ctorPrologue) { + EarlyReferenceKind erk = isAllowedEarlyReference(pos, env1, env1 == env, (VarSymbol)sym); + switch (erk) { + case UNDEFINED: + if (allowValueClasses) { + processUndefinedEarlyReference(pos.getTree(), env1, sym); + return sym; + } else { + return new RefBeforeCtorCalledError(sym); + } + case NOT_ACCEPTABLE: return new RefBeforeCtorCalledError(sym); - } else { - localProxyVarsGen.addStrictFieldReadInPrologue(env.enclMethod, sym); + case FIELD_HAS_INIT: + if (!allowValueClasses) { + return new RefBeforeCtorCalledError(sym, true); + } else { + // acceptable in valhalla + return sym; + } + default: return sym; - } } } } @@ -1586,6 +1602,16 @@ else if (!bestSoFar.kind.betterThan(VAR)) { return bestSoFar; } + void processUndefinedEarlyReference(JCTree tree, Env env, Symbol sym) { + /* at this point we don't have enough info, we could be seeing a sub tree which could + * be part of a select or something bigger + */ + JCTree originalTree = tree; + JCFieldAccess enclosingSelect = new FindEnclosingSelect().scan(tree, env.tree); + tree = enclosingSelect == null ? originalTree : enclosingSelect; + localProxyVarsGen.addASTReadInPrologue(env.enclMethod, tree); + } + Warner noteWarner = new Warner(); /** Select the best method for a call site among two choices. @@ -3826,7 +3852,7 @@ Symbol findSelfContaining(DiagnosticPosition pos, if (staticOnly) { // current class is not an inner class, stop search return new StaticError(sym); - } else if (env1.info.ctorPrologue && !isAllowedEarlyReference(pos, env1, (VarSymbol)sym)) { + } else if (env1.info.ctorPrologue && isAllowedEarlyReference(pos, env1, env1 == env, (VarSymbol)sym) != EarlyReferenceKind.ACCEPTABLE) { // early construction context, stop search return new RefBeforeCtorCalledError(sym); } else { @@ -3887,8 +3913,27 @@ Symbol resolveSelf(DiagnosticPosition pos, if (sym != null) { if (staticOnly) sym = new StaticError(sym); - else if (env1.info.ctorPrologue && !isAllowedEarlyReference(pos, env1, (VarSymbol)sym)) - sym = new RefBeforeCtorCalledError(sym); + else if (env1.info.ctorPrologue) { + EarlyReferenceKind erk = isAllowedEarlyReference(pos, env1, env1 == env, (VarSymbol)sym); + switch (erk) { + case UNDEFINED: + if (allowValueClasses) { + processUndefinedEarlyReference(pos.getTree(), env1, sym); + } else { + sym = new RefBeforeCtorCalledError(sym); + } + break; + case NOT_ACCEPTABLE: + sym = new RefBeforeCtorCalledError(sym); + break; + case FIELD_HAS_INIT: + if (!allowValueClasses) { + sym = new RefBeforeCtorCalledError(sym, true); + } + break; + default: // do nothing + } + } return accessBase(sym, pos, env.enclClass.sym.type, name, true); } @@ -3924,6 +3969,28 @@ else if (env1.info.ctorPrologue && !isAllowedEarlyReference(pos, env1, (VarSymbo return syms.errSymbol; } //where + public class FindEnclosingSelect extends TreeScanner { + JCTree treeToLookFor; + JCFieldAccess enclosingSelect = null; + + public JCFieldAccess scan(JCTree treeToLookFor, JCTree tree) { + this.treeToLookFor = treeToLookFor; + super.scan(tree); + return enclosingSelect; + } + + @Override + public void visitSelect(JCFieldAccess tree) { + if (tree.selected == treeToLookFor) { + enclosingSelect = tree; + // this select could be part of an enclosing select + treeToLookFor = tree; + } else { + scan(tree.selected); + } + } + } + private List pruneInterfaces(Type t) { ListBuffer result = new ListBuffer<>(); for (Type t1 : types.interfaces(t)) { @@ -3956,19 +4023,19 @@ private List pruneInterfaces(Type t) { * We also don't verify that the field has no initializer, which is required. * To catch those cases, we rely on similar logic in Attr.checkAssignable(). */ - private boolean isAllowedEarlyReference(DiagnosticPosition pos, Env env, VarSymbol v) { - + private EarlyReferenceKind isAllowedEarlyReference(DiagnosticPosition pos, Env env, boolean originalEnv, VarSymbol v) { // Check assumptions Assert.check(env.info.ctorPrologue); Assert.check((v.flags_field & STATIC) == 0); + // The assignment statement must not be within a lambda or a local class + if (env.info.isLambda || !originalEnv) { + return EarlyReferenceKind.NOT_ACCEPTABLE; + } + // The symbol must appear in the LHS of an assignment statement if (!(env.tree instanceof JCAssign assign)) - return false; - - // The assignment statement must not be within a lambda - if (env.info.isLambda) - return false; + return EarlyReferenceKind.UNDEFINED; // Get the symbol's qualifier, if any JCExpression lhs = TreeInfo.skipParens(assign.lhs); @@ -3980,23 +4047,44 @@ private boolean isAllowedEarlyReference(DiagnosticPosition pos, Env case SELECT: JCFieldAccess select = (JCFieldAccess)lhs; base = select.selected; - if (!TreeInfo.isExplicitThisReference(types, (ClassType)env.enclClass.type, base)) - return false; + if (!TreeInfo.isExplicitThisOrSuperReference(types, (ClassType)env.enclClass.type, base)) + return EarlyReferenceKind.NOT_ACCEPTABLE; break; default: - return false; + return EarlyReferenceKind.NOT_ACCEPTABLE; } // If an early reference, the field must not be declared in a superclass if (isEarlyReference(env, base, v) && v.owner != env.enclClass.sym) - return false; + return EarlyReferenceKind.NOT_ACCEPTABLE; // The flexible constructors feature must be enabled preview.checkSourceLevel(pos, Feature.FLEXIBLE_CONSTRUCTORS); - // OK - return true; + /* Field may not have an initializer, example: + * class C { + * int x = 1; + * public C() { + * x = 2; + * super(); + * } + * } + * in valhalla we want to allow for this as we execute initializers before the super invocation + */ + if ((v.flags() & HASINIT) != 0) { + return EarlyReferenceKind.FIELD_HAS_INIT; + } else { + // Acceptable + return EarlyReferenceKind.ACCEPTABLE; + } } + // where + enum EarlyReferenceKind { + ACCEPTABLE, + UNDEFINED, // can't tell with the current info + FIELD_HAS_INIT, // this is an error in JDK, acceptable in valhalla + NOT_ACCEPTABLE, // this is a not acceptable state for the method above + } /** * Determine if the variable appearance constitutes an early reference to the current class. @@ -4018,7 +4106,7 @@ public boolean isEarlyReference(Env env, JCTree base, VarSymbol v) (v.flags() & STATIC) == 0 && v.owner.kind == TYP && types.isSubtype(env.enclClass.type, v.owner.type) && - (base == null || TreeInfo.isExplicitThisReference(types, (ClassType)env.enclClass.type, base)); + (base == null || TreeInfo.isExplicitThisOrSuperReference(types, (ClassType)env.enclClass.type, base)); } /* *************************************************************************** @@ -4771,8 +4859,15 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, */ class RefBeforeCtorCalledError extends StaticError { + boolean hasInitializer; + RefBeforeCtorCalledError(Symbol sym) { + this(sym, false); + } + + RefBeforeCtorCalledError(Symbol sym, boolean hasInitializer) { super(sym, "prologue error"); + this.hasInitializer = hasInitializer; } @Override @@ -4786,8 +4881,13 @@ JCDiagnostic getDiagnostic(JCDiagnostic.DiagnosticType dkind, Symbol errSym = ((sym.kind == TYP && sym.type.hasTag(CLASS)) ? types.erasure(sym.type).tsym : sym); - return diags.create(dkind, log.currentSource(), pos, - "cant.ref.before.ctor.called", errSym); + return diags.create(dkind, + log.currentSource(), + pos, + !hasInitializer ? + "cant.ref.before.ctor.called" : + "cant.assign.initialized.before.ctor.called", + errSym); } } diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java index 77ddd5c6583..bf239954f93 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ThisEscapeAnalyzer.java @@ -52,7 +52,6 @@ import com.sun.tools.javac.code.Type; import com.sun.tools.javac.code.Types; import com.sun.tools.javac.resources.CompilerProperties.LintWarnings; -import com.sun.tools.javac.resources.CompilerProperties.Warnings; import com.sun.tools.javac.tree.JCTree; import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.TreeInfo; @@ -975,7 +974,7 @@ public void visitSelect(JCFieldAccess tree) { // Explicit 'this' reference? The expression references whatever 'this' references Type.ClassType currentClassType = (Type.ClassType)methodClass.sym.type; - if (TreeInfo.isExplicitThisReference(types, currentClassType, tree)) { + if (TreeInfo.isExplicitThisOrSuperReference(types, currentClassType, tree)) { refs.find(ThisRef.class) .map(ref -> new ExprRef(depth, ref)) .forEach(refs::add); diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java index bb8e257b17f..df2db781ef6 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/main/JavaCompiler.java @@ -55,7 +55,6 @@ import com.sun.source.util.TaskEvent; import com.sun.tools.javac.api.MultiTaskListener; import com.sun.tools.javac.code.*; -import com.sun.tools.javac.code.Lint.LintCategory; import com.sun.tools.javac.code.Source.Feature; import com.sun.tools.javac.code.Symbol.ClassSymbol; import com.sun.tools.javac.code.Symbol.CompletionFailure; @@ -80,7 +79,6 @@ import com.sun.tools.javac.util.DefinedBy.Api; import com.sun.tools.javac.util.JCDiagnostic.Factory; import com.sun.tools.javac.util.Log.DiagnosticHandler; -import com.sun.tools.javac.util.Log.DiscardDiagnosticHandler; import com.sun.tools.javac.util.Log.WriterKind; import static com.sun.tools.javac.code.Kinds.Kind.*; @@ -484,7 +482,8 @@ public boolean exists() { return false; } }; - + allowValueClasses = (!preview.isPreview(Feature.VALUE_CLASSES) || preview.isEnabled()) && + Feature.VALUE_CLASSES.allowedInSource(source); } /* Switches: @@ -572,6 +571,9 @@ public boolean exists() { */ private final Symbol silentFail; + /** Switch: are value classes allowed */ + private final boolean allowValueClasses; + protected boolean shouldStop(CompileState cs) { CompileState shouldStopPolicy = (errorCount() > 0 || unrecoverableError()) ? shouldStopPolicyIfError @@ -1546,8 +1548,6 @@ class ScanNested extends TreeScanner { Set> dependencies = new LinkedHashSet<>(); protected boolean hasLambdas; protected boolean hasPatterns; - protected boolean hasValueClasses; - protected boolean hasStrictFields; @Override public void visitClassDef(JCClassDecl node) { Type st = types.supertype(node.sym.type); @@ -1559,7 +1559,6 @@ public void visitClassDef(JCClassDecl node) { if (dependencies.add(stEnv)) { boolean prevHasLambdas = hasLambdas; boolean prevHasPatterns = hasPatterns; - boolean prevHasStrictFields = hasStrictFields; try { scan(stEnv.tree); } finally { @@ -1572,14 +1571,12 @@ public void visitClassDef(JCClassDecl node) { */ hasLambdas = prevHasLambdas; hasPatterns = prevHasPatterns; - hasStrictFields = prevHasStrictFields; } } envForSuperTypeFound = true; } st = types.supertype(st); } - hasValueClasses = node.sym.isValueClass(); super.visitClassDef(node); } @Override @@ -1619,12 +1616,6 @@ public void visitSwitchExpression(JCSwitchExpression tree) { hasPatterns |= tree.patternSwitch; super.visitSwitchExpression(tree); } - - @Override - public void visitVarDef(JCVariableDecl tree) { - hasStrictFields |= tree.sym.isStrict(); - super.visitVarDef(tree); - } } ScanNested scanner = new ScanNested(); scanner.scan(env.tree); @@ -1710,13 +1701,13 @@ public void visitVarDef(JCVariableDecl tree) { compileStates.put(env, CompileState.UNLAMBDA); } - if (scanner.hasValueClasses || scanner.hasStrictFields) { - if (shouldStop(CompileState.STRICT_FIELDS_PROXIES)) + if (allowValueClasses) { + if (shouldStop(CompileState.FIELDS_PROXIES)) return; for (JCTree def : cdefs) { LocalProxyVarsGen.instance(context).translateTopLevelClass(def, localMake); } - compileStates.put(env, CompileState.STRICT_FIELDS_PROXIES); + compileStates.put(env, CompileState.FIELDS_PROXIES); } //generate code for each class diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java index 5e3b043fb11..fc963a5d962 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeInfo.java @@ -31,7 +31,6 @@ import com.sun.source.util.TreePath; import com.sun.tools.javac.code.*; import com.sun.tools.javac.code.Symbol.RecordComponent; -import com.sun.tools.javac.comp.AttrContext; import com.sun.tools.javac.comp.Env; import com.sun.tools.javac.tree.JCTree.*; import com.sun.tools.javac.tree.JCTree.JCPolyExpression.*; @@ -189,10 +188,10 @@ public static boolean isIdentOrThisDotIdent(JCTree tree) { * - A 'this' identifier qualified by a class name whose type is 'currentClass' or a supertype * but also NOT an enclosing outer class of 'currentClass'. */ - public static boolean isExplicitThisReference(Types types, Type.ClassType currentClass, JCTree tree) { + public static boolean isExplicitThisOrSuperReference(Types types, Type.ClassType currentClass, JCTree tree) { switch (tree.getTag()) { case PARENS: - return isExplicitThisReference(types, currentClass, skipParens(tree)); + return isExplicitThisOrSuperReference(types, currentClass, skipParens(tree)); case IDENT: { JCIdent ident = (JCIdent)tree; Names names = ident.name.table.names; diff --git a/test/langtools/tools/javac/LocalClassCtorPrologue.java b/test/langtools/tools/javac/LocalClassCtorPrologue.java index 2a7178ed857..7b4e2b44815 100644 --- a/test/langtools/tools/javac/LocalClassCtorPrologue.java +++ b/test/langtools/tools/javac/LocalClassCtorPrologue.java @@ -29,4 +29,35 @@ class Local { super(); } } + + class Inner2 { + Inner2() { + class Sup { + int x; + } + class Local extends Sup { + Local() { + x = 42; // x is declared in a super type, error + super(); + } + } + super(); + } + } + + class Inner3 { + Inner3() { + class Local { + class Foo { + int x; + + Foo() { + x = 42; // this is OK `x` belongs to Foo + super(); + } + } + } + super(); + } + } } diff --git a/test/langtools/tools/javac/LocalClassCtorPrologue.out b/test/langtools/tools/javac/LocalClassCtorPrologue.out index 65f3418825d..f3445bf29bf 100644 --- a/test/langtools/tools/javac/LocalClassCtorPrologue.out +++ b/test/langtools/tools/javac/LocalClassCtorPrologue.out @@ -1,4 +1,5 @@ LocalClassCtorPrologue.java:16:17: compiler.err.cant.ref.before.ctor.called: x +LocalClassCtorPrologue.java:40:21: compiler.err.cant.ref.before.ctor.called: x - compiler.note.preview.filename: LocalClassCtorPrologue.java, DEFAULT - compiler.note.preview.recompile -1 error +2 errors diff --git a/test/langtools/tools/javac/SuperInit/EarlyAssignments.java b/test/langtools/tools/javac/SuperInit/EarlyAssignments.java index c3cad5d7016..43926b93aaa 100644 --- a/test/langtools/tools/javac/SuperInit/EarlyAssignments.java +++ b/test/langtools/tools/javac/SuperInit/EarlyAssignments.java @@ -10,6 +10,26 @@ public class EarlyAssignments { public static class Inner1 { public int x; + public Inner1(int y) { + y = x; // OK mutable field + super(); + } + + public Inner1(int y, int ignore1) { + y = this.x; // OK mutable field + super(); + } + + public Inner1(int y, boolean ignore2) { + y = Inner1.this.x; // OK mutable field + super(); + } + + public Inner1(short[] x) { + this.x++; // OK mutable field + super(); + } + public Inner1() { x = 123; // OK - "x" belongs to this class this.x = 123; // OK - "x" belongs to this class @@ -17,13 +37,6 @@ public Inner1() { super(); } - public Inner1(int y) { - y = x; // FAIL - early 'this' reference - y = this.x; // FAIL - early 'this' reference - y = Inner1.this.x; // FAIL - early 'this' reference - super(); - } - public class Inner1a extends Inner1 { public int z; public Inner1a(byte value) { @@ -95,13 +108,13 @@ public static class Inner4 { public Inner4() { x = 0; // OK - x = x + 1; // FAIL - illegal early access + x = x + 1; // OK super(); } public Inner4(int a) { this.x = 0; // OK - this.x = this.x + 1; // FAIL - illegal early access + this.x = this.x + 1; // OK super(); } diff --git a/test/langtools/tools/javac/SuperInit/EarlyAssignments.out b/test/langtools/tools/javac/SuperInit/EarlyAssignments.out index 38182c2d312..afa06d03298 100644 --- a/test/langtools/tools/javac/SuperInit/EarlyAssignments.out +++ b/test/langtools/tools/javac/SuperInit/EarlyAssignments.out @@ -1,29 +1,22 @@ -EarlyAssignments.java:21:17: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:22:17: compiler.err.cant.ref.before.ctor.called: this -EarlyAssignments.java:23:23: compiler.err.cant.ref.before.ctor.called: this -EarlyAssignments.java:31:21: compiler.err.cant.ref.before.ctor.called: super -EarlyAssignments.java:32:21: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:33:26: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:34:34: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:36:36: compiler.err.cant.ref.before.ctor.called: this -EarlyAssignments.java:40:17: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:44:21: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:48:22: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:66:13: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:67:17: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:68:25: compiler.err.cant.ref.before.ctor.called: this -EarlyAssignments.java:69:31: compiler.err.cant.ref.before.ctor.called: this -EarlyAssignments.java:98:17: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:104:22: compiler.err.cant.ref.before.ctor.called: this -EarlyAssignments.java:110:35: compiler.err.cant.ref.before.ctor.called: this -EarlyAssignments.java:119:17: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:124:22: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:129:29: compiler.err.cant.ref.before.ctor.called: x -EarlyAssignments.java:134:17: compiler.err.cant.ref.before.ctor.called: super -EarlyAssignments.java:139:23: compiler.err.cant.ref.before.ctor.called: this -EarlyAssignments.java:148:13: compiler.err.cant.assign.initialized.before.ctor.called: x -EarlyAssignments.java:157:13: compiler.err.cant.assign.val.to.var: final, x -EarlyAssignments.java:168:13: compiler.err.cant.ref.before.ctor.called: this +EarlyAssignments.java:44:26: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:45:21: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:46:26: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:47:34: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:49:36: compiler.err.cant.ref.before.ctor.called: this +EarlyAssignments.java:53:17: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:57:21: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:61:22: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:79:13: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:80:17: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:81:25: compiler.err.cant.ref.before.ctor.called: this +EarlyAssignments.java:82:31: compiler.err.cant.ref.before.ctor.called: this +EarlyAssignments.java:132:17: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:137:22: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:142:29: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:147:22: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:152:28: compiler.err.cant.ref.before.ctor.called: x +EarlyAssignments.java:170:13: compiler.err.cant.assign.val.to.var: final, x +EarlyAssignments.java:181:13: compiler.err.cant.ref.before.ctor.called: this - compiler.note.preview.filename: EarlyAssignments.java, DEFAULT - compiler.note.preview.recompile -26 errors +19 errors diff --git a/test/langtools/tools/javac/SuperInit/SuperInitFails.java b/test/langtools/tools/javac/SuperInit/SuperInitFails.java index feb5b81c1b0..70d53a3cf15 100644 --- a/test/langtools/tools/javac/SuperInit/SuperInitFails.java +++ b/test/langtools/tools/javac/SuperInit/SuperInitFails.java @@ -90,11 +90,6 @@ public SuperInitFails(char[] x) { super(); } - public SuperInitFails(short[] x) { - this.x++; // this should FAIL - super(); - } - public SuperInitFails(float[] x) { System.identityHashCode(this); // this should FAIL super(); diff --git a/test/langtools/tools/javac/SuperInit/SuperInitFails.out b/test/langtools/tools/javac/SuperInit/SuperInitFails.out index 4394a6741c3..63cb7610d9f 100644 --- a/test/langtools/tools/javac/SuperInit/SuperInitFails.out +++ b/test/langtools/tools/javac/SuperInit/SuperInitFails.out @@ -1,26 +1,26 @@ SuperInitFails.java:57:9: compiler.err.cant.ref.before.ctor.called: hashCode() -SuperInitFails.java:62:9: compiler.err.cant.ref.before.ctor.called: this -SuperInitFails.java:67:9: compiler.err.cant.ref.before.ctor.called: super -SuperInitFails.java:72:23: compiler.err.cant.ref.before.ctor.called: this -SuperInitFails.java:77:23: compiler.err.cant.ref.before.ctor.called: super -SuperInitFails.java:94:9: compiler.err.cant.ref.before.ctor.called: this -SuperInitFails.java:99:33: compiler.err.cant.ref.before.ctor.called: this -SuperInitFails.java:104:14: compiler.err.cant.ref.before.ctor.called: this -SuperInitFails.java:108:20: compiler.err.not.encl.class: java.lang.Object -SuperInitFails.java:112:17: compiler.err.cant.ref.before.ctor.called: super -SuperInitFails.java:119:22: compiler.err.call.must.only.appear.in.ctor -SuperInitFails.java:125:9: compiler.err.cant.ref.before.ctor.called: this -SuperInitFails.java:133:9: compiler.err.non.canonical.constructor.invoke.another.constructor: SuperInitFails.Record1 -SuperInitFails.java:138:9: compiler.err.non.canonical.constructor.invoke.another.constructor: SuperInitFails.Record2 -SuperInitFails.java:155:31: compiler.err.cant.ref.before.ctor.called: x -SuperInitFails.java:159:15: compiler.err.cant.ref.before.ctor.called: this -SuperInitFails.java:168:13: compiler.err.cant.ref.before.ctor.called: x -SuperInitFails.java:172:17: compiler.err.cant.ref.before.ctor.called: x -SuperInitFails.java:176:24: compiler.err.cant.ref.before.ctor.called: x -SuperInitFails.java:180:18: compiler.err.cant.ref.before.ctor.called: x -SuperInitFails.java:195:25: compiler.err.return.before.superclass.initialized -SuperInitFails.java:200:33: compiler.err.ctor.calls.not.allowed.here -SuperInitFails.java:205:29: compiler.err.redundant.superclass.init +SuperInitFails.java:62:13: compiler.err.cant.ref.before.ctor.called: hashCode() +SuperInitFails.java:67:14: compiler.err.cant.ref.before.ctor.called: hashCode() +SuperInitFails.java:72:28: compiler.err.cant.ref.before.ctor.called: hashCode() +SuperInitFails.java:77:29: compiler.err.cant.ref.before.ctor.called: hashCode() +SuperInitFails.java:94:33: compiler.err.cant.ref.before.ctor.called: this +SuperInitFails.java:99:14: compiler.err.cant.ref.before.ctor.called: this +SuperInitFails.java:103:20: compiler.err.not.encl.class: java.lang.Object +SuperInitFails.java:107:17: compiler.err.cant.ref.before.ctor.called: super +SuperInitFails.java:114:22: compiler.err.call.must.only.appear.in.ctor +SuperInitFails.java:120:9: compiler.err.cant.ref.before.ctor.called: this +SuperInitFails.java:128:9: compiler.err.non.canonical.constructor.invoke.another.constructor: SuperInitFails.Record1 +SuperInitFails.java:133:9: compiler.err.non.canonical.constructor.invoke.another.constructor: SuperInitFails.Record2 +SuperInitFails.java:150:31: compiler.err.cant.ref.before.ctor.called: x +SuperInitFails.java:154:15: compiler.err.cant.ref.before.ctor.called: this +SuperInitFails.java:163:13: compiler.err.cant.ref.before.ctor.called: x +SuperInitFails.java:167:17: compiler.err.cant.ref.before.ctor.called: x +SuperInitFails.java:171:24: compiler.err.cant.ref.before.ctor.called: x +SuperInitFails.java:175:18: compiler.err.cant.ref.before.ctor.called: x +SuperInitFails.java:181:28: compiler.err.cant.ref.before.ctor.called: this +SuperInitFails.java:190:25: compiler.err.return.before.superclass.initialized +SuperInitFails.java:195:33: compiler.err.ctor.calls.not.allowed.here +SuperInitFails.java:200:29: compiler.err.redundant.superclass.init SuperInitFails.java:33:13: compiler.err.call.must.only.appear.in.ctor SuperInitFails.java:37:14: compiler.err.call.must.only.appear.in.ctor SuperInitFails.java:41:14: compiler.err.call.must.only.appear.in.ctor @@ -29,7 +29,7 @@ SuperInitFails.java:49:33: compiler.err.call.must.only.appear.in.ctor SuperInitFails.java:53:32: compiler.err.call.must.only.appear.in.ctor SuperInitFails.java:83:18: compiler.err.ctor.calls.not.allowed.here SuperInitFails.java:89:13: compiler.err.return.before.superclass.initialized -SuperInitFails.java:150:18: compiler.err.call.must.only.appear.in.ctor +SuperInitFails.java:145:18: compiler.err.call.must.only.appear.in.ctor - compiler.note.preview.filename: SuperInitFails.java, DEFAULT - compiler.note.preview.recompile 32 errors diff --git a/test/langtools/tools/javac/SuperInit/ValueClassSuperInitFails.out b/test/langtools/tools/javac/SuperInit/ValueClassSuperInitFails.out index 914a97b63aa..062c123e118 100644 --- a/test/langtools/tools/javac/SuperInit/ValueClassSuperInitFails.out +++ b/test/langtools/tools/javac/SuperInit/ValueClassSuperInitFails.out @@ -1,8 +1,8 @@ ValueClassSuperInitFails.java:67:9: compiler.err.cant.ref.before.ctor.called: hashCode() -ValueClassSuperInitFails.java:72:9: compiler.err.cant.ref.before.ctor.called: this -ValueClassSuperInitFails.java:77:9: compiler.err.cant.ref.before.ctor.called: super -ValueClassSuperInitFails.java:82:33: compiler.err.cant.ref.before.ctor.called: this -ValueClassSuperInitFails.java:87:33: compiler.err.cant.ref.before.ctor.called: super +ValueClassSuperInitFails.java:72:13: compiler.err.cant.ref.before.ctor.called: hashCode() +ValueClassSuperInitFails.java:77:14: compiler.err.cant.ref.before.ctor.called: hashCode() +ValueClassSuperInitFails.java:82:38: compiler.err.cant.ref.before.ctor.called: hashCode() +ValueClassSuperInitFails.java:87:39: compiler.err.cant.ref.before.ctor.called: hashCode() ValueClassSuperInitFails.java:109:33: compiler.err.cant.ref.before.ctor.called: this ValueClassSuperInitFails.java:114:14: compiler.err.cant.ref.before.ctor.called: this ValueClassSuperInitFails.java:118:20: compiler.err.not.encl.class: java.lang.Object @@ -12,6 +12,7 @@ ValueClassSuperInitFails.java:135:9: compiler.err.cant.ref.before.ctor.called: t ValueClassSuperInitFails.java:143:9: compiler.err.non.canonical.constructor.invoke.another.constructor: ValueClassSuperInitFails.Record1 ValueClassSuperInitFails.java:148:9: compiler.err.non.canonical.constructor.invoke.another.constructor: ValueClassSuperInitFails.Record2 ValueClassSuperInitFails.java:161:41: compiler.err.cant.ref.before.ctor.called: this +ValueClassSuperInitFails.java:175:49: compiler.err.cant.ref.before.ctor.called: x ValueClassSuperInitFails.java:179:15: compiler.err.cant.ref.before.ctor.called: this ValueClassSuperInitFails.java:43:13: compiler.err.call.must.only.appear.in.ctor ValueClassSuperInitFails.java:47:14: compiler.err.call.must.only.appear.in.ctor @@ -24,4 +25,4 @@ ValueClassSuperInitFails.java:99:13: compiler.err.return.before.superclass.initi ValueClassSuperInitFails.java:170:18: compiler.err.call.must.only.appear.in.ctor - compiler.note.preview.filename: ValueClassSuperInitFails.java, DEFAULT - compiler.note.preview.recompile -24 errors +25 errors diff --git a/test/langtools/tools/javac/T7093325.java b/test/langtools/tools/javac/T7093325.java index 2dfb171ea70..5e6dd5ae95a 100644 --- a/test/langtools/tools/javac/T7093325.java +++ b/test/langtools/tools/javac/T7093325.java @@ -32,6 +32,7 @@ * jdk.compiler/com.sun.tools.javac.util * @build combo.ComboTestHelper * @run main T7093325 + * @enablePreview */ import java.io.IOException; diff --git a/test/langtools/tools/javac/T8222949/TestConstantDynamic.java b/test/langtools/tools/javac/T8222949/TestConstantDynamic.java index 4578bfbf318..838ec171370 100644 --- a/test/langtools/tools/javac/T8222949/TestConstantDynamic.java +++ b/test/langtools/tools/javac/T8222949/TestConstantDynamic.java @@ -34,6 +34,7 @@ * jdk.compiler/com.sun.tools.javac.util * @build combo.ComboTestHelper * @run main TestConstantDynamic + * @enablePreview */ import java.io.IOException; diff --git a/test/langtools/tools/javac/diags/examples.not-yet.txt b/test/langtools/tools/javac/diags/examples.not-yet.txt index 2a909df2e3c..03c057e04c7 100644 --- a/test/langtools/tools/javac/diags/examples.not-yet.txt +++ b/test/langtools/tools/javac/diags/examples.not-yet.txt @@ -226,3 +226,4 @@ compiler.misc.feature.value.classes # Pending removal compiler.note.implicit.annotation.processing compiler.warn.proc.use.proc.or.implicit +compiler.err.cant.assign.initialized.before.ctor.called diff --git a/test/langtools/tools/javac/diags/examples/CantAssignInitializedBeforeCtorCalled.java b/test/langtools/tools/javac/diags/examples/CantWriteFieldFromLocalInPrologue.java similarity index 84% rename from test/langtools/tools/javac/diags/examples/CantAssignInitializedBeforeCtorCalled.java rename to test/langtools/tools/javac/diags/examples/CantWriteFieldFromLocalInPrologue.java index 55f5d19451d..a6b1e8b1a91 100644 --- a/test/langtools/tools/javac/diags/examples/CantAssignInitializedBeforeCtorCalled.java +++ b/test/langtools/tools/javac/diags/examples/CantWriteFieldFromLocalInPrologue.java @@ -23,13 +23,17 @@ // key: compiler.note.preview.filename // key: compiler.note.preview.recompile - // key: compiler.err.cant.assign.initialized.before.ctor.called + // key: compiler.err.cant.ref.before.ctor.called // options: --enable-preview -source ${jdk.version} -class CantAssignInitializedBeforeCtorCalled { - int x = 1; - CantAssignInitializedBeforeCtorCalled() { - x = 2; +class CantWriteFieldFromLocalInPrologue { + int x; + CantWriteFieldFromLocalInPrologue() { + class Local { + { + x++; + } + } super(); } } diff --git a/test/langtools/tools/javac/lambda/TestInvokeDynamic.java b/test/langtools/tools/javac/lambda/TestInvokeDynamic.java index b7e980d5726..1f60f9e9dae 100644 --- a/test/langtools/tools/javac/lambda/TestInvokeDynamic.java +++ b/test/langtools/tools/javac/lambda/TestInvokeDynamic.java @@ -35,6 +35,7 @@ * jdk.compiler/com.sun.tools.javac.tree * jdk.compiler/com.sun.tools.javac.util * @build combo.ComboTestHelper + * @enablePreview * @run main TestInvokeDynamic */ diff --git a/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecode.java b/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecode.java index 4c779b2b6c3..ab7f31b6d50 100644 --- a/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecode.java +++ b/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecode.java @@ -31,6 +31,7 @@ * jdk.compiler/com.sun.tools.javac.file * jdk.compiler/com.sun.tools.javac.util * @build combo.ComboTestHelper + * @enablePreview * @run main TestLambdaBytecode */ diff --git a/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecodeTargetRelease14.java b/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecodeTargetRelease14.java index ac67054d732..40fe216b27d 100644 --- a/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecodeTargetRelease14.java +++ b/test/langtools/tools/javac/lambda/bytecode/TestLambdaBytecodeTargetRelease14.java @@ -31,6 +31,7 @@ * jdk.compiler/com.sun.tools.javac.file * jdk.compiler/com.sun.tools.javac.util * @build combo.ComboTestHelper + * @enablePreview * @run main TestLambdaBytecodeTargetRelease14 */ diff --git a/test/langtools/tools/javac/preview/PreviewErrors.java b/test/langtools/tools/javac/preview/PreviewErrors.java index eab5b2af9bf..2a475f3ec30 100644 --- a/test/langtools/tools/javac/preview/PreviewErrors.java +++ b/test/langtools/tools/javac/preview/PreviewErrors.java @@ -33,6 +33,7 @@ * jdk.compiler/com.sun.tools.javac.main * jdk.compiler/com.sun.tools.javac.util * @build toolbox.ToolBox toolbox.JavacTask + * @enablePreview * @build combo.ComboTestHelper * @run main PreviewErrors */ diff --git a/test/langtools/tools/javac/valhalla/value-objects/ValueObjectCompilationTests.java b/test/langtools/tools/javac/valhalla/value-objects/ValueObjectCompilationTests.java index 1b8a03f5494..d3f9ccc2b22 100644 --- a/test/langtools/tools/javac/valhalla/value-objects/ValueObjectCompilationTests.java +++ b/test/langtools/tools/javac/valhalla/value-objects/ValueObjectCompilationTests.java @@ -919,11 +919,12 @@ value class V { } """ ); - assertOK( + assertFail("compiler.err.cant.ref.before.ctor.called", """ value class Test { Test t = null; - Runnable r = () -> { System.err.println(t); }; // compiler will generate a local proxy for `t` + // can't reference instance field from a lambda before super constructor has been invoked + Runnable r = () -> { System.err.println(t); }; } """ ); diff --git a/test/langtools/tools/javac/varargs/7042566/T7042566.java b/test/langtools/tools/javac/varargs/7042566/T7042566.java index 1f0e6b768ba..1dbbaa7adfc 100644 --- a/test/langtools/tools/javac/varargs/7042566/T7042566.java +++ b/test/langtools/tools/javac/varargs/7042566/T7042566.java @@ -31,6 +31,7 @@ * jdk.compiler/com.sun.tools.javac.file * jdk.compiler/com.sun.tools.javac.util * @build combo.ComboTestHelper + * @enablePreview * @run main T7042566 */