Skip to content

Commit

Permalink
Roll back non-essential changes from the fix for #1506 (#1563)
Browse files Browse the repository at this point in the history
Roll back non-essential changes from the fix for #1506 as they
trigger pre-existing bugs
  • Loading branch information
srikanth-sankaran authored Nov 6, 2023
1 parent b533aad commit 9997dbc
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ private static int checkInvocationArgument(BlockScope scope, Expression argument
if (allocExp.typeExpected == null && !allocExp.expectedTypeWasInferred) {
final boolean isDiamond = allocExp.type != null && (allocExp.type.bits & ASTNode.IsDiamond) != 0;
allocExp.typeExpected = parameterType;
if (!isDiamond && allocExp.type.resolvedType.isParameterizedTypeWithActualArguments()) {
ParameterizedTypeBinding ptb = (ParameterizedTypeBinding) allocExp.type.resolvedType;
allocExp.reportTypeArgumentRedundancyProblem(ptb, scope);
if (!isDiamond && allocExp.resolvedType.isParameterizedTypeWithActualArguments()) {
ParameterizedTypeBinding pbinding = (ParameterizedTypeBinding) allocExp.resolvedType;
scope.problemReporter().redundantSpecificationOfTypeArguments(allocExp.type, pbinding.arguments);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,12 +866,7 @@ public void testGH1506_3() {
+ " ^^\n"
+ "X.AX is a raw type. References to generic type X.AX<T> should be parameterized\n"
+ "----------\n"
+ "2. ERROR in X.java (at line 6)\n"
+ " X<? extends AX> x5 = new X<AX<String>>(new AX<String>() { private void foo() {} });\n"
+ " ^^\n"
+ "Redundant specification of type arguments <String>\n"
+ "----------\n"
+ "3. WARNING in X.java (at line 6)\n"
+ "2. WARNING in X.java (at line 6)\n"
+ " X<? extends AX> x5 = new X<AX<String>>(new AX<String>() { private void foo() {} });\n"
+ " ^^^^^\n"
+ "The method foo() from the type new X.AX<String>(){} is never used locally\n"
Expand Down Expand Up @@ -908,6 +903,110 @@ public void testGH1506_4() {
+ "----------\n",
null, true, options);
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1560
// ECJ recommends diamond when using it would result in non-denotable types.
public void testGH1560() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR);
this.runNegativeTest(
new String[] {
"X.java",
"""
import java.util.Collection;
import java.util.List;
public class X<S, D> {
public interface MMenuElement {}
public interface IObservable {}
public static class ListDiffVisitor<E> {}
public interface IObservablesListener {}
public interface IObservableCollection<E> extends IObservable, Collection<E> {}
public static class ObservableEvent {}
public interface IDiff {}
public static class ListDiff<E> implements IDiff {
public void accept(ListDiffVisitor<? super E> visitor) {}
}
public static class ListChangeEvent<E> extends ObservableEvent {
public ListDiff<E> diff;
}
public interface IListChangeListener<E> extends IObservablesListener {
void handleListChange(ListChangeEvent<? extends E> event);
}
public interface IObservableList<E> extends List<E>, IObservableCollection<E> {
void addListChangeListener(IListChangeListener<? super E> listener);
}
public void foo() {
IObservableList<MMenuElement> l;
l.addListChangeListener(event -> event.diff.accept(new ListDiffVisitor<MMenuElement>() {})); // <> should not be recommended here!!!
}
}
""",
},
"----------\n"
+ "1. ERROR in X.java (at line 30)\n"
+ " l.addListChangeListener(event -> event.diff.accept(new ListDiffVisitor<MMenuElement>() {})); // <> should not be recommended here!!!\n"
+ " ^\n"
+ "The local variable l may not have been initialized\n"
+ "----------\n",
null, true, options);
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1560
// ECJ recommends diamond when using it would result in non-denotable types.
public void testGH1560_2() {
Map<String, String> options = getCompilerOptions();
options.put(CompilerOptions.OPTION_ReportRedundantSpecificationOfTypeArguments, CompilerOptions.ERROR);
this.runNegativeTest(
new String[] {
"X.java",
"""
import java.util.Collection;
import java.util.List;
public class X<S, D> {
public interface MMenuElement {}
public interface IObservable {}
public static class ListDiffVisitor<E> {}
public interface IObservablesListener {}
public interface IObservableCollection<E> extends IObservable, Collection<E> {}
public static class ObservableEvent {}
public interface IDiff {}
public static class ListDiff<E> implements IDiff {
public void accept(ListDiffVisitor<? super E> visitor) {}
}
public static class ListChangeEvent<E> extends ObservableEvent {
public ListDiff<E> diff;
}
public interface IListChangeListener<E> extends IObservablesListener {
void handleListChange(ListChangeEvent<? extends E> event);
}
public interface IObservableList<E> extends List<E>, IObservableCollection<E> {
void addListChangeListener(IListChangeListener<? super E> listener);
}
public void foo() {
IObservableList<MMenuElement> l;
l.addListChangeListener(event -> event.diff.accept(new ListDiffVisitor<>() {})); // non-denotable type error
}
}
""",
},
"----------\n"
+ "1. ERROR in X.java (at line 30)\n"
+ " l.addListChangeListener(event -> event.diff.accept(new ListDiffVisitor<>() {})); // non-denotable type error\n"
+ " ^^^^^^^^^^^^^^^\n"
+ "Type X.ListDiffVisitor<capture#1-of ? extends X.MMenuElement> inferred for ListDiffVisitor<>, is not valid for an anonymous class with '<>'\n"
+ "----------\n",
null, true, options);
}
public static Class<GenericsRegressionTest_9> testClass() {
return GenericsRegressionTest_9.class;
}
Expand Down

0 comments on commit 9997dbc

Please sign in to comment.