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 36b0a37e9a..7d469770ad 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 @@ -1,5 +1,5 @@ /* - * Copyright 2009-2019 the original author or authors. + * Copyright 2009-2020 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -112,4 +112,22 @@ public void testTypeChecked4() { runNegativeTest(sources, ""); } + + @Test + public void testTypeChecked5() { + //@formatter:off + String[] sources = { + "Foo.groovy", + "@groovy.transform.TypeChecked\n" + + "class Foo {\n" + + " private Closure normalizer\n" + + " String normalize(String s) {\n" + + " normalizer(s)" + + " }\n" + + "}\n", + }; + //@formatter:on + + runNegativeTest(sources, ""); + } } diff --git a/base/org.codehaus.groovy24/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/base/org.codehaus.groovy24/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index e499693982..efee2fef4f 100644 --- a/base/org.codehaus.groovy24/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/base/org.codehaus.groovy24/src/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -3189,7 +3189,10 @@ public void visitMethodCallExpression(MethodCallExpression call) { boolean callArgsVisited = false; if (isCallOnClosure) { // this is a closure.call() call - if (objectExpression == VariableExpression.THIS_EXPRESSION) { + // GRECLIPSE edit + //if (objectExpression == VariableExpression.THIS_EXPRESSION) { + if (objectExpression instanceof VariableExpression && ((VariableExpression) objectExpression).isThisExpression()) { + // GRECLIPSE end // isClosureCall() check verified earlier that a field exists FieldNode field = typeCheckingContext.getEnclosingClassNode().getDeclaredField(name); GenericsType[] genericsTypes = field.getType().getGenericsTypes(); @@ -3571,7 +3574,10 @@ protected void storeTargetMethod(final Expression call, final MethodNode directM protected boolean isClosureCall(final String name, final Expression objectExpression, final Expression arguments) { if (objectExpression instanceof ClosureExpression && ("call".equals(name)||"doCall".equals(name))) return true; - if (objectExpression == VariableExpression.THIS_EXPRESSION) { + // GRECLIPSE edit + //if (objectExpression == VariableExpression.THIS_EXPRESSION) { + if (objectExpression instanceof VariableExpression && ((VariableExpression) objectExpression).isThisExpression()) { + // GRECLIPSE end FieldNode fieldNode = typeCheckingContext.getEnclosingClassNode().getDeclaredField(name); if (fieldNode != null) { ClassNode type = fieldNode.getType(); 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 e57636dcb0..90d04668a5 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 @@ -3322,7 +3322,10 @@ public void visitMethodCallExpression(MethodCallExpression call) { boolean callArgsVisited = false; if (isCallOnClosure) { // this is a closure.call() call - if (objectExpression == VariableExpression.THIS_EXPRESSION) { + // GRECLIPSE edit + //if (objectExpression == VariableExpression.THIS_EXPRESSION) { + if (objectExpression instanceof VariableExpression && ((VariableExpression) objectExpression).isThisExpression()) { + // GRECLIPSE end // isClosureCall() check verified earlier that a field exists FieldNode field = typeCheckingContext.getEnclosingClassNode().getDeclaredField(name); GenericsType[] genericsTypes = field.getType().getGenericsTypes(); @@ -3719,7 +3722,10 @@ protected void storeTargetMethod(final Expression call, final MethodNode directM protected boolean isClosureCall(final String name, final Expression objectExpression, final Expression arguments) { if (objectExpression instanceof ClosureExpression && ("call".equals(name) || "doCall".equals(name))) return true; - if (objectExpression == VariableExpression.THIS_EXPRESSION) { + // GRECLIPSE edit + //if (objectExpression == VariableExpression.THIS_EXPRESSION) { + if (objectExpression instanceof VariableExpression && ((VariableExpression) objectExpression).isThisExpression()) { + // GRECLIPSE end FieldNode fieldNode = typeCheckingContext.getEnclosingClassNode().getDeclaredField(name); if (fieldNode != null) { ClassNode type = fieldNode.getType();