Permalink
Browse files

GROOVY-8033: spread property calls on non-list collections fail STC i…

…n static methods (closes #476)
  • Loading branch information...
1 parent d05ecc9 commit 1d68627120b15bed726f666912c784a30843e10c @shils shils committed with shils Jan 4, 2017
@@ -1373,6 +1373,7 @@ private MethodNode findGetter(ClassNode current, String name, boolean searchOute
private ClassNode getTypeForSpreadExpression(ClassNode testClass, ClassNode objectExpressionType, PropertyExpression pexp) {
if (!pexp.isSpreadSafe()) return null;
MethodCallExpression mce = new MethodCallExpression(new VariableExpression("_", testClass), "iterator", ArgumentListExpression.EMPTY_ARGUMENTS);
+ mce.setImplicitThis(false);
mce.visit(this);
ClassNode callType = getType(mce);
if (!implementsInterfaceOrIsSubclassOf(callType, Iterator_TYPE)) return null;
@@ -557,5 +557,19 @@ class ArraysAndCollectionsSTCTest extends StaticTypeCheckingTestCase {
countIt([1,2,3])==3
'''
}
+
+ // GROOVY-8033
+ void testSetSpreadPropertyInStaticContext() {
+ assertScript '''
+ class Foo {
+ String name
+ }
+ static List<String> meth() {
+ Set<Foo> foos = [new Foo(name: 'pls'), new Foo(name: 'bar')].toSet()
+ foos*.name
+ }
+ assert meth().toSet() == ['pls', 'bar'].toSet()
+ '''
+ }
}

0 comments on commit 1d68627

Please sign in to comment.