Skip to content

Commit

Permalink
GROOVY-10309, GROOVY-10315
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 1, 2021
1 parent d1a6999 commit e540810
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4215,6 +4215,54 @@ public void testTypeChecked10306() {
runConformTest(sources, "1");
}

@Test
public void testTypeChecked10309() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.TupleConstructor(defaults=false)\n" +
"class A<T,T2> {\n" +
" T f1\n" +
" T2 f2\n" +
"}\n" +
"class C<T,X> {\n" +
" @groovy.transform.TypeChecked\n" +
" void test() {\n" +
" new A<X,T>((X)null, (T)null)\n" + // Cannot call A#<init>(X, T) with arguments [X, T]
" }\n" +
"}\n" +
"new C().test()",
};
//@formatter:on

runConformTest(sources);
}

@Test
public void testTypeChecked10315() {
for (String args : new String[] {"m2(), c.m()", "c.m(), m2()"}) {
//@formatter:off
String[] sources = {
"Main.groovy",
"class C<T> {\n" +
" def T m() {\n" +
" }\n" +
"}\n" +
"def <X> X m2() {\n" +
"}\n" +
"def <Y> void m3(Y y1, Y y2) {\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"def <Z> void test(C<Z> c) {\n" +
" m3(" + args + ")\n" +
"}\n",
};
//@formatter:on

runConformTest(sources);
}
}

@Test
public void testTypeChecked10320() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1719,8 +1719,15 @@ static void applyGenericsConnections(final Map<GenericsTypeName, GenericsType> c
GenericsTypeName name = new GenericsTypeName(oldValue.getName());
GenericsType newValue = connections.get(name); // find "V" in T=V
if (newValue == oldValue) continue;
// GRECLIPSE add -- GROOVY-10067
if (name.getName().charAt(0) == '#') continue;
// GRECLIPSE add -- GROOVY-10067, GROOVY-10315
if (newValue == null) {
newValue = connections.get(entry.getKey());
if (newValue != null) {
ClassNode o = GenericsUtils.makeClassSafe0(CLASS_Type, oldValue),
n = GenericsUtils.makeClassSafe0(CLASS_Type, newValue);
newValue = WideningCategories.lowestUpperBound(o,n).getGenericsTypes()[0];
}
}
// GRECLIPSE end
if (newValue == null) {
entry.setValue(newValue = applyGenericsContext(connections, oldValue));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
import static org.apache.groovy.ast.tools.ExpressionUtils.isNullConstant;
import static org.codehaus.groovy.ast.ClassHelper.BigInteger_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.Byte_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.CLASS_Type;
import static org.codehaus.groovy.ast.ClassHelper.CLOSURE_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.COLLECTION_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.Character_TYPE;
Expand Down Expand Up @@ -118,6 +119,7 @@
import static org.codehaus.groovy.ast.ClassHelper.makeWithoutCaching;
import static org.codehaus.groovy.ast.ClassHelper.short_TYPE;
import static org.codehaus.groovy.ast.ClassHelper.void_WRAPPER_TYPE;
import static org.codehaus.groovy.ast.tools.GenericsUtils.makeClassSafe0;
import static org.codehaus.groovy.ast.tools.WideningCategories.isBigIntCategory;
import static org.codehaus.groovy.ast.tools.WideningCategories.isFloatingCategory;
import static org.codehaus.groovy.ast.tools.WideningCategories.isNumberCategory;
Expand Down Expand Up @@ -1607,9 +1609,17 @@ static void applyGenericsConnections(final Map<GenericsTypeName, GenericsType> c
if (oldValue.isPlaceholder()) { // T=T or V, not T=String or ? ...
GenericsTypeName name = new GenericsTypeName(oldValue.getName());
GenericsType newValue = connections.get(name); // find "V" in T=V
if (newValue == oldValue || name.getName().charAt(0) == '#') continue;
if (newValue == oldValue) continue;
if (newValue == null) { // GROOVY-10315
newValue = connections.get(entry.getKey());
if (newValue != null) {
ClassNode o = makeClassSafe0(CLASS_Type, oldValue),
n = makeClassSafe0(CLASS_Type, newValue);
newValue = lowestUpperBound(o,n).getGenericsTypes()[0];
}
}
if (newValue == null) {
entry.setValue(newValue = applyGenericsContext(connections, oldValue));
entry.setValue(newValue = applyGenericsContext(connections, oldValue));
if (!checkForMorePlaceholders) {
checkForMorePlaceholders = !equalIncludingGenerics(oldValue, newValue);
}
Expand Down

0 comments on commit e540810

Please sign in to comment.