Skip to content

Commit d05ff88

Browse files
authored
Merge branch 'eclipse-jdt:master' into master
2 parents 1391e62 + b58677b commit d05ff88

4 files changed

Lines changed: 77 additions & 7 deletions

File tree

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/TypeDeclaration.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, Fl
264264
}
265265
manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo);
266266
updateMaxFieldCount(); // propagate down the max field count
267-
internalAnalyseCode(flowContext, flowInfo.unconditionalFieldLessCopy()); // discards info about fields of enclosing classes
267+
internalAnalyseCode(flowContext, flowInfo);
268268
} catch (AbortType e) {
269269
this.ignoreFurtherInvestigation = true;
270270
}
@@ -300,7 +300,7 @@ public void analyseCode(ClassScope currentScope, FlowContext flowContext, FlowIn
300300
}
301301
manageEnclosingInstanceAccessIfNecessary(currentScope, flowInfo);
302302
updateMaxFieldCount(); // propagate down the max field count
303-
internalAnalyseCode(flowContext, flowInfo.unconditionalFieldLessCopy()); // discards info about fields of enclosing classes
303+
internalAnalyseCode(flowContext, flowInfo);
304304
} catch (AbortType e) {
305305
this.ignoreFurtherInvestigation = true;
306306
}
@@ -744,8 +744,8 @@ private void internalAnalyseCode(FlowContext flowContext, FlowInfo flowInfo) {
744744
InitializationFlowContext initializerContext = new InitializationFlowContext(parentContext, this, flowInfo, flowContext, this.initializerScope);
745745
// no static initializer in local classes, thus no need to set parent:
746746
InitializationFlowContext staticInitializerContext = new InitializationFlowContext(null, this, flowInfo, flowContext, this.staticInitializerScope);
747-
FlowInfo nonStaticFieldInfo = flowInfo.copy();
748-
FlowInfo staticFieldInfo = flowInfo.copy();
747+
FlowInfo nonStaticFieldInfo = flowInfo.unconditionalFieldLessCopy(); // discards info about fields of inclosing classes
748+
FlowInfo staticFieldInfo = flowInfo.unconditionalFieldLessCopy();
749749

750750
if (JavaFeature.FLEXIBLE_CONSTRUCTOR_BODIES.isSupported(this.scope.compilerOptions())) {
751751
if (this.methods != null) {
@@ -755,7 +755,7 @@ private void internalAnalyseCode(FlowContext flowContext, FlowInfo flowInfo) {
755755
for (int i=0; i<this.methods.length; i++) {
756756
AbstractMethodDeclaration method = this.methods[i];
757757
if (method.isConstructor()) {
758-
FlowInfo ctorInfo = flowInfo.copy();
758+
FlowInfo ctorInfo = flowInfo.unconditionalFieldLessCopy();
759759
ConstructorDeclaration constructor = (ConstructorDeclaration) method;
760760
constructor.analyseCode(this.scope, initializerContext, ctorInfo, ctorInfo.reachMode(), AnalysisMode.PROLOGUE);
761761
ctorInfo = constructor.getPrologueInfo();
@@ -856,7 +856,7 @@ private void internalAnalyseCode(FlowContext flowContext, FlowInfo flowInfo) {
856856
}
857857
}
858858
if (this.methods != null) {
859-
FlowInfo outerInfo = flowInfo.copy();
859+
UnconditionalFlowInfo outerInfo = flowInfo.unconditionalFieldLessCopy();
860860
if (nonStaticFieldInfo instanceof UnconditionalDualFlowInfo udfi) {
861861
nonStaticFieldInfo = udfi.getMainInits(); // drop info from prologues
862862
} else if (nonStaticFieldInfo instanceof DualFlowInfo dfi) {

org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/CaptureBinding.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,9 @@ public void initializeBounds(Scope scope, ParameterizedTypeBinding capturedParam
307307
if(scope.environment().usesNullTypeAnnotations()) {
308308
evaluateNullAnnotations(scope, null);
309309
}
310-
this.compatibleCache = null; // any checks during initialization may have produced bogus results, get rid of them now
310+
if (this.compatibleCache != null) {
311+
this.compatibleCache.clear(); // any checks during initialization may have produced bogus results, get rid of them now
312+
}
311313
}
312314

313315
@Override

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericsRegressionTest_9.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,46 @@ interface MyCallable<U, F extends Exception> extends Callable<U> {
20342034
});
20352035
}
20362036

2037+
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/4864
2038+
// Cannot infer type arguments with ecj 3.44.0 but not with 3.43.0
2039+
public void testIssue4864() {
2040+
runConformTest(new String[] {
2041+
"X.java",
2042+
"""
2043+
import java.util.Locale;
2044+
2045+
public class X {
2046+
2047+
interface TypeConverter<T> {
2048+
T convert(String s) throws Exception;
2049+
}
2050+
2051+
class EnumConverter<E extends Enum<E>> implements TypeConverter<E> {
2052+
private Class<E> clazz;
2053+
2054+
EnumConverter(Class<E> clazz) {
2055+
this.clazz = clazz;
2056+
}
2057+
2058+
@Override
2059+
public E convert(String s) {
2060+
return valueOf(clazz, s);
2061+
}
2062+
2063+
<T extends Enum<T>> T valueOf(Class<T> enumType, String name) {
2064+
return Enum.valueOf(enumType, name.toUpperCase(Locale.ENGLISH));
2065+
}
2066+
}
2067+
2068+
TypeConverter<?> findCompatibleConverter(Class<?> clazz) {
2069+
EnumConverter<? extends Enum> converter = new EnumConverter<>(clazz.asSubclass(Enum.class));
2070+
return converter;
2071+
}
2072+
}
2073+
"""
2074+
});
2075+
}
2076+
20372077
public static Class<GenericsRegressionTest_9> testClass() {
20382078
return GenericsRegressionTest_9.class;
20392079
}

org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InitializationTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,34 @@ public class Test {
669669
"""
670670
});
671671
}
672+
public void testGH4865() {
673+
runConformTest(new String[] {
674+
"Foo.java",
675+
"""
676+
import java.util.Comparator;
677+
public class Foo {
678+
private final String greeting;
679+
680+
public Foo() {
681+
this.greeting = "Hello";
682+
683+
Comparator<String> comp = new Comparator<String>() {
684+
685+
{
686+
System.out.println(greeting);
687+
}
688+
689+
@Override
690+
public int compare(String o1, String o2) {
691+
System.out.println(greeting);
692+
return o1.compareTo(o2);
693+
}
694+
};
695+
}
696+
}
697+
"""
698+
});
699+
}
672700
public static Class testClass() {
673701
return InitializationTests.class;
674702
}

0 commit comments

Comments
 (0)