Repository: groovy Updated Branches: refs/heads/GROOVY_2_4_X f5cc12d6e -> d04c3ad95
GROOVY-6835: flow typing activated by if statement doing an "instanceof" check doesn't work as expected with interface types (test only) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/d04c3ad9 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/d04c3ad9 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/d04c3ad9 Branch: refs/heads/GROOVY_2_4_X Commit: d04c3ad955bd109aefe758a3d67b817d8e5c4c95 Parents: f5cc12d Author: paulk <pa...@asert.com.au> Authored: Tue Jan 5 13:12:22 2016 +1000 Committer: paulk <pa...@asert.com.au> Committed: Tue Jan 5 13:13:41 2016 +1000 ---------------------------------------------------------------------- .../transform/stc/TypeInferenceSTCTest.groovy | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/d04c3ad9/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy index 9dadeb8..d1f61d8 100644 --- a/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy +++ b/src/test/groovy/transform/stc/TypeInferenceSTCTest.groovy @@ -736,6 +736,24 @@ Thing.run() ''' } + // GROOVY-6835 + void testFlowTypingWithInstanceofAndInterfaceTypes() { + assertScript ''' + class ShowUnionTypeBug { + Map<String, Object> instanceMap = (Map<String,Object>)['a': 'Hello World'] + def findInstance(String key) { + Set<? extends CharSequence> allInstances = [] as Set + def instance = instanceMap.get(key) + if(instance instanceof CharSequence) { + allInstances.add(instance) + } + allInstances + } + } + assert new ShowUnionTypeBug().findInstance('a') == ['Hello World'] as Set + ''' + } + void testInferenceWithImplicitClosureCoercionAndGenericTypeAsParameter() { assertScript ''' interface Action<T> { void execute(T t) }