diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java index a556419af5..94ef5e8afc 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/xform/TypeCheckedTests.java @@ -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"); + } } diff --git a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 4f441bbd90..ca3603dd94 100644 --- a/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy25/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -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; diff --git a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 8dde999ed5..8eaeb381ff 100644 --- a/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy30/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -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); } diff --git a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index 47a5a8cc1a..1735345b2d 100644 --- a/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy40/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -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(); @@ -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 @@ -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 @@ -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); }