From 06e84dfb7a5a7e4af119f38a59c157d6907f703d Mon Sep 17 00:00:00 2001 From: Shil Sinha Date: Mon, 28 Dec 2015 17:16:09 -0500 Subject: [PATCH] GROOVY-7702: @CompileStatic and the method with(Closure) seem to determine wrong type --- .../transform/stc/StaticTypeCheckingVisitor.java | 2 +- .../transform/stc/FieldsAndPropertiesSTCTest.groovy | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java index ecaecf789c4..bf428afdbdb 100644 --- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java +++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java @@ -1225,7 +1225,7 @@ protected boolean existsProperty(final PropertyExpression pexp, final boolean re if (storeProperty(propertyNode, pexp, current, visitor, receiver.getData())) return true; boolean isThisExpression = objectExpression instanceof VariableExpression && - ((VariableExpression) objectExpression).isThisExpression(); + ((VariableExpression) objectExpression).isThisExpression() && objectExpressionType.equals(current); if (storeField(field, isThisExpression, pexp, receiver.getType(), visitor, receiver.getData())) return true; diff --git a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy index f12b555e7cc..90ce986cde3 100644 --- a/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy +++ b/src/test/groovy/transform/stc/FieldsAndPropertiesSTCTest.groovy @@ -568,7 +568,7 @@ class FooWorker { } } -new FooWorker().doSomething()''', 'Incompatible generic argument types. Cannot assign java.util.ArrayList to: java.util.List ' +new FooWorker().doSomething()''', 'Cannot assign value of type java.util.ArrayList to variable of type java.util.List ' } void testAICAsStaticProperty() { @@ -731,6 +731,14 @@ import org.codehaus.groovy.ast.stmt.AssertStatement ''' } + void testImplicitPropertyOfDelegateShouldNotPreferField() { + assertScript ''' + Calendar.instance.with { + Date d1 = time + } + ''' + } + public static interface InterfaceWithField { String boo = "I don't fancy fields in interfaces" }