Skip to content

Commit

Permalink
The method public static KeySetView<K,java.lang.Boolean> newKeySet() is
Browse files Browse the repository at this point in the history
wrongly tagged as containing missing types

Avoid tagging the method, when the target type has a missing type

Tentatively turn the syserrs into assert false : "message"

Fixes #3501
  • Loading branch information
stephan-herrmann committed Feb 11, 2025
1 parent 668fa97 commit 7aae1d5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,10 @@ public static MethodBinding computeCompatibleMethod18(MethodBinding originalMeth
if (invocationSite instanceof Invocation && allArgumentsAreProper && (expectedType == null || expectedType.isProperType(true)))
infCtx18.forwardResults(result, (Invocation) invocationSite, methodSubstitute, expectedType);
try {
if (infCtx18.hasIgnoredMissingType) {
if (infCtx18.hasIgnoredMissingType
&& (expectedType == null
|| (expectedType.tagBits & TagBits.HasMissingType) == 0)) // don't blame the method, when it's the expected type having problems
{
return new ProblemMethodBinding(originalMethod, originalMethod.selector, parameters, ProblemReasons.MissingTypeInSignature);
}
if (hasReturnProblem) { // illegally working from the provisional result?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6921,7 +6921,7 @@ public void missingSynchronizedOnInheritedMethod(MethodBinding currentMethod, Me
public void missingTypeInConstructor(ASTNode location, MethodBinding constructor) {
List<TypeBinding> missingTypes = constructor.collectMissingTypes(null, true);
if (missingTypes == null) {
System.err.println("The constructor " + constructor + " is wrongly tagged as containing missing types"); //$NON-NLS-1$ //$NON-NLS-2$
assert false : "The constructor " + constructor + " is wrongly tagged as containing missing types"; //$NON-NLS-1$ //$NON-NLS-2$
return;
}
TypeBinding missingType = missingTypes.get(0);
Expand Down Expand Up @@ -6954,7 +6954,7 @@ public void missingTypeInLambda(LambdaExpression lambda, MethodBinding method) {
int nameSourceEnd = lambda.diagnosticsSourceEnd();
List<TypeBinding> missingTypes = method.collectMissingTypes(null, true);
if (missingTypes == null) {
System.err.println("The lambda expression " + method + " is wrongly tagged as containing missing types"); //$NON-NLS-1$ //$NON-NLS-2$
assert false : "The lambda expression " + method + " is wrongly tagged as containing missing types"; //$NON-NLS-1$ //$NON-NLS-2$
return;
}
TypeBinding missingType = missingTypes.get(0);
Expand All @@ -6981,7 +6981,7 @@ public void missingTypeInMethod(ASTNode astNode, MethodBinding method) {
}
List<TypeBinding> missingTypes = method.collectMissingTypes(null, true);
if (missingTypes == null) {
System.err.println("The method " + method + " is wrongly tagged as containing missing types"); //$NON-NLS-1$ //$NON-NLS-2$
assert false : "The method " + method + " is wrongly tagged as containing missing types"; //$NON-NLS-1$ //$NON-NLS-2$
return;
}
TypeBinding missingType = missingTypes.get(0);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2016, 2021 IBM Corporation.
* Copyright (c) 2016, 2025 IBM Corporation.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -1025,6 +1025,30 @@ default void test() {
};
runner.runConformTest();
}
public void testGH3501() {
Runner runner = new Runner();
runner.testFiles = new String[] {
"X.java",
"""
import java.util.Collections;
public class X {
void test() {
Zork v = Collections.singleton("1");
}
}
"""
};
runner.expectedCompilerLog =
"""
----------
1. ERROR in X.java (at line 4)
Zork v = Collections.singleton("1");
^^^^
Zork cannot be resolved to a type
----------
""";
runner.runNegativeTest();
}
public static Class<GenericsRegressionTest_9> testClass() {
return GenericsRegressionTest_9.class;
}
Expand Down

0 comments on commit 7aae1d5

Please sign in to comment.