Skip to content

Commit

Permalink
GROOVY-10324
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Nov 1, 2021
1 parent d47b4aa commit 41556b2
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4348,6 +4348,25 @@ public void testTypeChecked10323() {
"----------\n");
}

@Test
public void testTypeChecked10324() {
//@formatter:off
String[] sources = {
"Main.groovy",
"class C<T> {\n" +
"}\n" +
"def <X> X m(C<X> c) {\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"void test() {\n" +
" Set<String> x = m(new C<>())\n" +
"}\n",
};
//@formatter:on

runNegativeTest(sources, "");
}

@Test
public void testTypeChecked10325() {
//@formatter:off
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -982,13 +982,13 @@ && isAssignment(enclosingBinaryExpression.getOperation().getType())) {
if (rightExpression instanceof ConstructorCallExpression) {
inferDiamondType((ConstructorCallExpression) rightExpression, lType);
}
// GRECLIPSE add -- unchecked assignment
// GRECLIPSE add -- GROOVY-10051, GROOVY-10235, GROOVY-10324
if (lType.isUsingGenerics() && missesGenericsTypes(resultType)) {
// the inferred type of the binary expression is the type of the RHS
// "completed" with generics type information available from the LHS
if (lType.equals(resultType)) {
if (!lType.isGenericsPlaceHolder()) resultType = lType;
} else {
} else if (!resultType.isGenericsPlaceHolder()) {
Map<GenericsTypeName, GenericsType> gt = new HashMap<>();
extractGenericsConnections(gt, resultType, resultType.redirect());
extractGenericsConnections(gt, lType, getNextSuperClass(resultType, lType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,13 +867,13 @@ && isAssignment(enclosingBinaryExpression.getOperation().getType())) {
if (rightExpression instanceof ConstructorCallExpression) {
inferDiamondType((ConstructorCallExpression) rightExpression, lType);
}
// GRECLIPSE add -- unchecked assignment
// GRECLIPSE add -- GROOVY-10051, GROOVY-10235, GROOVY-10324
if (lType.isUsingGenerics() && missesGenericsTypes(resultType)) {
// the inferred type of the binary expression is the type of the RHS
// "completed" with generics type information available from the LHS
if (lType.equals(resultType)) {
if (!lType.isGenericsPlaceHolder()) resultType = lType;
} else {
} else if (!resultType.isGenericsPlaceHolder()) {
Map<GenericsTypeName, GenericsType> gt = new HashMap<>();
extractGenericsConnections(gt, resultType, resultType.redirect());
extractGenericsConnections(gt, lType, getNextSuperClass(resultType, lType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -866,13 +866,13 @@ && isAssignment(enclosingBinaryExpression.getOperation().getType())) {

// the inferred type of the binary expression is the type of the RHS
// "completed" with generics type information available from the LHS
/* GRECLIPSE edit -- GROOVY-10235
/* GRECLIPSE edit -- GROOVY-10051, GROOVY-10235, GROOVY-10324
if (!resultType.isGenericsPlaceHolder()) // plain reference drops placeholder
resultType = GenericsUtils.parameterizeType(lType, resultType.getPlainNodeReference());
*/
if (lType.equals(resultType)) {
if (!lType.isGenericsPlaceHolder()) resultType = lType;
} else {
} else if (!resultType.isGenericsPlaceHolder()) {
Map<GenericsTypeName, GenericsType> gt = new HashMap<>();
extractGenericsConnections(gt, resultType, resultType.redirect());
extractGenericsConnections(gt, lType, getNextSuperClass(resultType, lType));
Expand Down

0 comments on commit 41556b2

Please sign in to comment.