Skip to content

Commit

Permalink
GROOVY-10667
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Jun 27, 2022
1 parent 0817dcf commit e352da5
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5899,4 +5899,35 @@ public void testTypeChecked10662() {

runConformTest(sources);
}

@Test
public void testTypeChecked10667() {
//@formatter:off
String[] sources = {
"Main.groovy",
"trait Tagged {\n" +
" String tag\n" +
"}\n" +
"class TaggedException extends Exception implements Tagged {\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"void accept1(Exception e) {\n" +
" if (e instanceof Tagged) {\n" +
" print e.tag\n" +
" accept2(e)\n" + // Cannot find matching method #accept2(Tagged)
" }\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"void accept2(Exception e) {\n" +
"}\n" +
"@groovy.transform.TypeChecked\n" +
"void test() {\n" +
" accept1(new TaggedException(tag:'foo'))\n" +
"}\n" +
"test()\n",
};
//@formatter:on

runConformTest(sources, "foo");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2879,7 +2879,11 @@ protected ClassNode[] getArgumentTypes(ArgumentListExpression args) {
if (isNullConstant(exp)) {
ret[i] = UNKNOWN_PARAMETER_TYPE;
} else {
/* GRECLIPSE edit -- GROOVY-10667
ret[i] = getInferredTypeFromTempInfo(exp, getType(exp));
*/
ret[i] = getType(exp);
// GRECLIPSE end
}
}
return ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2679,7 +2679,11 @@ protected MethodNode typeCheckMapConstructor(final ConstructorCallExpression cal

protected ClassNode[] getArgumentTypes(final ArgumentListExpression args) {
return args.getExpressions().stream().map(exp ->
/* GRECLIPSE edit -- GROOVY-10667
isNullConstant(exp) ? UNKNOWN_PARAMETER_TYPE : getInferredTypeFromTempInfo(exp, getType(exp))
*/
isNullConstant(exp) ? UNKNOWN_PARAMETER_TYPE : getType(exp)
// GRECLIPSE end
).toArray(ClassNode[]::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -763,10 +763,9 @@ public void visitBinaryExpression(final BinaryExpression expression) {
typeCheckingContext.pushEnclosingBinaryExpression(expression);
try {
int op = expression.getOperation().getType();
// GRECLIPSE add -- GROOVY-7971
if (op == LOGICAL_OR) {
// GRECLIPSE add -- GROOVY-7971, GROOVY-8965
if (op == LOGICAL_OR)
typeCheckingContext.pushTemporaryTypeInfo();
}
// GRECLIPSE end
Expression leftExpression = expression.getLeftExpression();
Expression rightExpression = expression.getRightExpression();
Expand All @@ -776,7 +775,7 @@ public void visitBinaryExpression(final BinaryExpression expression) {
ClassNode lType = null;
if (setterInfo != null) {
if (ensureValidSetter(expression, leftExpression, rightExpression, setterInfo)) {
// GRECLIPSE add -- GROOVY-7971
// GRECLIPSE add -- GROOVY-7971, GROOVY-8965
if (op == LOGICAL_OR)
typeCheckingContext.popTemporaryTypeInfo();
// GRECLIPSE end
Expand Down Expand Up @@ -815,7 +814,7 @@ public void visitBinaryExpression(final BinaryExpression expression) {

resultType = getType(fullExpression);
}
// GRECLIPSE add -- GROOVY-7971
// GRECLIPSE add -- GROOVY-7971, GROOVY-8965
else if (op == LOGICAL_OR)
typeCheckingContext.popTemporaryTypeInfo();
// GRECLIPSE end
Expand Down Expand Up @@ -2395,7 +2394,11 @@ protected MethodNode typeCheckMapConstructor(final ConstructorCallExpression cal

protected ClassNode[] getArgumentTypes(final ArgumentListExpression args) {
return args.getExpressions().stream().map(exp ->
/* GRECLIPSE edit -- GROOVY-10667
isNullConstant(exp) ? UNKNOWN_PARAMETER_TYPE : getInferredTypeFromTempInfo(exp, getType(exp))
*/
isNullConstant(exp) ? UNKNOWN_PARAMETER_TYPE : getType(exp)
// GRECLIPSE end
).toArray(ClassNode[]::new);
}

Expand Down

0 comments on commit e352da5

Please sign in to comment.