You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/01/05 04:12:35 UTC
groovy git commit: GROOVY-6835: flow typing activated by if statement
doing an "instanceof" check doesn't work as expected with interface types
(test only)
Repository: groovy
Updated Branches:
refs/heads/master de272e5fb -> 586a316da
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/586a316d
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/586a316d
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/586a316d
Branch: refs/heads/master
Commit: 586a316daae55e80a7c0eb1ed8f96b1277044de2
Parents: de272e5
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:12:22 2016 +1000
----------------------------------------------------------------------
.../transform/stc/TypeInferenceSTCTest.groovy | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/586a316d/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) }