Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
2.3.2, 2.4.0-rc-1
-
None
Description
The following code example fails with this STC error in compilation:
1 compilation error:
[Static type checking] - Cannot call java.util.Set <CharSequence>#add(java.lang.CharSequence) with arguments [<UnionTypejava.lang.Object+java.lang.CharSequence>]
at line: 10, column: 12
@groovy.transform.CompileStatic class ShowUnionTypeBug { Map<String, Object> instanceMap = (Map<String,Object>)['a': 'Hello World'] def findInstance(String key) { Set<CharSequence> allInstances = [] as Set def instance = instanceMap.get(key) if(instance instanceof CharSequence) { allInstances.add(instance) } allInstances } } new ShowUnionTypeBug().findInstance('a')
Attachments
Issue Links
- is related to
-
GROOVY-9074 CompileStatic does not throw expected exception
- Resolved