Skip to content

Commit

Permalink
GROOVY-9948
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 18, 2021
1 parent 412a64f commit fc4caf4
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -891,4 +891,25 @@ public void testTypeChecked9945() {

runConformTest(sources, "42");
}

@Test
public void testTypeChecked9948() {
//@formatter:off
String[] sources = {
"Main.groovy",
"@groovy.transform.TupleConstructor\n" +
"class C<T> {\n" +
" T p\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"void test() {\n" +
" C<Integer> c = new C<>(1)\n" +
" print(c.p < 10)\n" +
"}\n" +
"test()\n",
};
//@formatter:on

runConformTest(sources, "true");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1111,20 +1111,33 @@ protected ClassNode getOriginalDeclarationType(Expression lhs) {
}

protected void inferDiamondType(final ConstructorCallExpression cce, final ClassNode lType) {
ClassNode cceType = cce.getType(), inferredType = lType;
// check if constructor call expression makes use of the diamond operator
ClassNode node = cce.getType();
if (node.isUsingGenerics() && node.getGenericsTypes() != null && node.getGenericsTypes().length == 0) {
if (cceType.getGenericsTypes() != null && cceType.getGenericsTypes().length == 0) {
ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
/* GRECLIPSE edit -- GROOVY-9948
if (argumentListExpression.getExpressions().isEmpty()) {
adjustGenerics(lType, node);
adjustGenerics(lType, cceType);
} else {
ClassNode type = getType(argumentListExpression.getExpression(0));
if (type.isUsingGenerics()) {
adjustGenerics(type, node);
adjustGenerics(type, cceType);
}
}
// store inferred type on CCE
storeType(cce, node);
storeType(cce, cceType);
*/
ConstructorNode constructor = cce.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET);
if (!argumentListExpression.getExpressions().isEmpty() && constructor != null) {
ClassNode type = GenericsUtils.parameterizeType(cceType, cceType);
type = inferReturnTypeGenerics(type, constructor, argumentListExpression);
if (type.isUsingGenerics()) {
inferredType = type;
}
}
adjustGenerics(inferredType, cceType);
storeType(cce, cceType);
// GRECLIPSE end
}
}

Expand Down Expand Up @@ -5441,7 +5454,7 @@ protected ClassNode inferReturnTypeGenerics(
MethodNode method,
Expression arguments,
GenericsType[] explicitTypeHints) {
ClassNode returnType = method.getReturnType();
ClassNode returnType = method instanceof ConstructorNode ? method.getDeclaringClass() : method.getReturnType(); // GRECLIPSE edit -- GROOVY-9948
if (method instanceof ExtensionMethodNode
&& (isUsingGenericsOrIsArrayUsingGenerics(returnType))) {
// check if the placeholder corresponds to the placeholder of the first parameter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1046,20 +1046,34 @@ protected ClassNode getOriginalDeclarationType(final Expression lhs) {
}

protected void inferDiamondType(final ConstructorCallExpression cce, final ClassNode lType) {
ClassNode cceType = cce.getType(), inferredType = lType;
// check if constructor call expression makes use of the diamond operator
ClassNode node = cce.getType();
if (node.isUsingGenerics() && node.getGenericsTypes() != null && node.getGenericsTypes().length == 0) {
if (cceType.getGenericsTypes() != null && cceType.getGenericsTypes().length == 0) {
/* GRECLIPSE edit -- GROOVY-9948
ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
if (argumentListExpression.getExpressions().isEmpty()) {
adjustGenerics(lType, node);
adjustGenerics(lType, cceType);
} else {
ClassNode type = getType(argumentListExpression.getExpression(0));
if (type.isUsingGenerics()) {
adjustGenerics(type, node);
adjustGenerics(type, cceType);
}
}
// store inferred type on CCE
storeType(cce, node);
storeType(cce, cceType);
*/
ArgumentListExpression argumentList = InvocationWriter.makeArgumentList(cce.getArguments());
ConstructorNode constructor = cce.getNodeMetaData(DIRECT_METHOD_CALL_TARGET);
if (!argumentList.getExpressions().isEmpty() && constructor != null) {
ClassNode type = GenericsUtils.parameterizeType(cceType, cceType);
type = inferReturnTypeGenerics(type, constructor, argumentList);
if (type.isUsingGenerics()) {
inferredType = type;
}
}
adjustGenerics(inferredType, cceType);
storeType(cce, cceType);
// GRECLIPSE end
}
}

Expand Down Expand Up @@ -5226,7 +5240,7 @@ protected ClassNode inferReturnTypeGenerics(final ClassNode receiver, final Meth
* @return parameterized, infered, class node
*/
protected ClassNode inferReturnTypeGenerics(final ClassNode receiver, final MethodNode method, final Expression arguments, final GenericsType[] explicitTypeHints) {
ClassNode returnType = method.getReturnType();
ClassNode returnType = method instanceof ConstructorNode ? method.getDeclaringClass() : method.getReturnType(); // GRECLIPSE edit -- GROOVY-9948
if (getGenericsWithoutArray(returnType) == null) {
return returnType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1044,20 +1044,34 @@ protected ClassNode getOriginalDeclarationType(final Expression lhs) {
}

protected void inferDiamondType(final ConstructorCallExpression cce, final ClassNode lType) {
ClassNode cceType = cce.getType(), inferredType = lType;
// check if constructor call expression makes use of the diamond operator
ClassNode node = cce.getType();
if (node.isUsingGenerics() && node.getGenericsTypes() != null && node.getGenericsTypes().length == 0) {
if (cceType.getGenericsTypes() != null && cceType.getGenericsTypes().length == 0) {
/* GRECLIPSE edit -- GROOVY-9948
ArgumentListExpression argumentListExpression = InvocationWriter.makeArgumentList(cce.getArguments());
if (argumentListExpression.getExpressions().isEmpty()) {
adjustGenerics(lType, node);
adjustGenerics(lType, cceType);
} else {
ClassNode type = getType(argumentListExpression.getExpression(0));
if (type.isUsingGenerics()) {
adjustGenerics(type, node);
adjustGenerics(type, cceType);
}
}
// store inferred type on CCE
storeType(cce, node);
storeType(cce, cceType);
*/
ArgumentListExpression argumentList = InvocationWriter.makeArgumentList(cce.getArguments());
ConstructorNode constructor = cce.getNodeMetaData(DIRECT_METHOD_CALL_TARGET);
if (!argumentList.getExpressions().isEmpty() && constructor != null) {
ClassNode type = GenericsUtils.parameterizeType(cceType, cceType);
type = inferReturnTypeGenerics(type, constructor, argumentList);
if (type.isUsingGenerics()) {
inferredType = type;
}
}
adjustGenerics(inferredType, cceType);
storeType(cce, cceType);
// GRECLIPSE end
}
}

Expand Down Expand Up @@ -5192,7 +5206,7 @@ protected ClassNode inferReturnTypeGenerics(final ClassNode receiver, final Meth
* @return parameterized, infered, class node
*/
protected ClassNode inferReturnTypeGenerics(final ClassNode receiver, final MethodNode method, final Expression arguments, final GenericsType[] explicitTypeHints) {
ClassNode returnType = method.getReturnType();
ClassNode returnType = method instanceof ConstructorNode ? method.getDeclaringClass() : method.getReturnType(); // GRECLIPSE edit -- GROOVY-9948
if (getGenericsWithoutArray(returnType) == null) {
return returnType;
}
Expand Down

0 comments on commit fc4caf4

Please sign in to comment.