Skip to content

Commit

Permalink
GROOVY-8033: spread property calls on non-list collections fail STC i…
Browse files Browse the repository at this point in the history
…n static methods (closes #476)
  • Loading branch information
shils committed Jan 9, 2017
1 parent d05ecc9 commit 1d68627
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions src/test/groovy/transform/stc/ArraysAndCollectionsSTCTest.groovy
Expand Up @@ -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.