From d0085088b2d81ad8dc5ea7c3dc3aec632698db6d Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Thu, 12 Dec 2024 12:58:21 +0000 Subject: [PATCH] Initial push --- .../com/sun/tools/javac/code/Type.java | 40 ++++++------------- .../com/sun/tools/javac/comp/Infer.java | 1 - .../recovery/CrashDueToUnreportedError.out | 2 +- 3 files changed, 13 insertions(+), 30 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java index 7bcef30a3f9af..497210150ad28 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Type.java @@ -2004,11 +2004,11 @@ public UndetVar(TypeVar origin, UndetVarListener listener, Types types) { bounds.put(InferenceBound.EQ, List.nil()); for (Type t : declaredBounds.reverse()) { //add bound works in reverse order - addBound(InferenceBound.UPPER, t, types, true); + addBound(InferenceBound.UPPER, t, types); } if (origin.isCaptured() && !origin.lower.hasTag(BOT)) { //add lower bound if needed - addBound(InferenceBound.LOWER, origin.lower, types, true); + addBound(InferenceBound.LOWER, origin.lower, types); } } @@ -2070,7 +2070,7 @@ public void dupTo(UndetVar uv2, Types types) { for (InferenceBound ib : InferenceBound.values()) { uv2.bounds.put(ib, List.nil()); for (Type t : getBounds(ib)) { - uv2.addBound(ib, t, types, true); + uv2.addBound(ib, t, types); } } uv2.inst = inst; @@ -2130,31 +2130,15 @@ public void setBounds(InferenceBound ib, List newBounds) { /** add a bound of a given kind - this might trigger listener notification */ public final void addBound(InferenceBound ib, Type bound, Types types) { - addBound(ib, bound, types, false); - } - - @SuppressWarnings("fallthrough") - private void addBound(InferenceBound ib, Type bound, Types types, boolean update) { - if (kind == Kind.CAPTURED && !update) { - //Captured inference variables bounds must not be updated during incorporation, - //except when some inference variable (beta) has been instantiated in the - //right-hand-side of a 'C = capture(C) constraint. - if (bound.hasTag(UNDETVAR) && !((UndetVar)bound).isCaptured()) { - //If the new incoming bound is itself a (regular) inference variable, - //then we are allowed to propagate this inference variable bounds to it. - ((UndetVar)bound).addBound(ib.complement(), this, types, false); - } - } else { - Type bound2 = bound.map(toTypeVarMap).baseType(); - List prevBounds = bounds.get(ib); - if (bound == qtype) return; - for (Type b : prevBounds) { - //check for redundancy - do not add same bound twice - if (types.isSameType(b, bound2)) return; - } - bounds.put(ib, prevBounds.prepend(bound2)); - notifyBoundChange(ib, bound2, false); + Type bound2 = bound.map(toTypeVarMap).baseType(); + List prevBounds = bounds.get(ib); + if (bound == qtype) return; + for (Type b : prevBounds) { + //check for redundancy - do not add same bound twice + if (types.isSameType(b, bound2)) return; } + bounds.put(ib, prevBounds.prepend(bound2)); + notifyBoundChange(ib, bound2, false); } //where TypeMapping toTypeVarMap = new StructuralTypeMapping() { @@ -2191,7 +2175,7 @@ public void substBounds(List from, List to, Types types) { bounds.put(ib, newBounds.toList()); //step 3 - for each dependency, add new replaced bound for (Type dep : deps) { - addBound(ib, types.subst(dep, from, to), types, true); + addBound(ib, types.subst(dep, from, to), types); } } } finally { diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java index d590c62f27f8a..84eae77bbf3b4 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java @@ -1104,7 +1104,6 @@ public void varInstantiated(UndetVar uv) { @Override public void varBoundChanged(UndetVar uv, InferenceBound ib, Type bound, boolean update) { - if (uv.isCaptured()) return; uv.incorporationActions.addAll(getIncorporationActions(uv, ib, bound, update)); } diff --git a/test/langtools/tools/javac/recovery/CrashDueToUnreportedError.out b/test/langtools/tools/javac/recovery/CrashDueToUnreportedError.out index 83655eb07baae..75bff72006b45 100644 --- a/test/langtools/tools/javac/recovery/CrashDueToUnreportedError.out +++ b/test/langtools/tools/javac/recovery/CrashDueToUnreportedError.out @@ -1,2 +1,2 @@ -CrashDueToUnreportedError.java:14:43: compiler.err.prob.found.req: (compiler.misc.infer.no.conforming.assignment.exists: E,compiler.misc.type.captureof: 1, ? extends CrashDueToUnreportedError.Entity,Root, (compiler.misc.inconvertible.types: java.util.List>, java.util.List>)) +CrashDueToUnreportedError.java:14:20: compiler.err.cant.apply.symbol: kindname.constructor, Builder, CrashDueToUnreportedError.Person,java.lang.String, CrashDueToUnreportedError.Person, kindname.class, CrashDueToUnreportedError.Builder, (compiler.misc.arg.length.mismatch) 1 error