Description
In version 3.0.10 normally the following code worked fine:
import groovy.transform.CompileStatic @CompileStatic class Test { def toArray(Object value) { def res if (value instanceof List) res = (value as List).toArray() else if (value instanceof String || value instanceof GString) res = value.toString().split(',') else throw new Exception("Not support!") return res } } println new Test().toArray([1,2,3]) println new Test().toArray('1,2,3')
In version 3.0.11, the code does not compile with the following error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: ideaGroovyConsole.groovy: 10: [Static type checking] - Reference to method is ambiguous. Cannot choose between [java.lang.String java.lang.String#toString(), java.lang.String groovy.lang.GString#toString()] @ line 10, column 33. res = value.toString().split(',') ^ ideaGroovyConsole.groovy: 10: [Static type checking] - Cannot find matching method java.lang.Object#split(java.lang.String). Please check if the declared type is correct and if the method exists. @ line 10, column 19. res = value.toString().split(',') ^
If you remove value instanceof GString from "if", then the code compiles and runs.
Attachments
Issue Links
- duplicates
-
GROOVY-7971 @CS flow typing incorrectly casting to map at runtime
- In Progress
-
GROOVY-8965 instanceof with || inserts wrong cast
- Closed
- is caused by
-
GROOVY-10180 STC: instanceof and DGM each(Map,Closure)
- Closed