-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type inferencing error (only in Eclipse, not in groovyc) #1281
Comments
It is this change where the raw type Line 5740 in 74e24d8
As a workaround, you can add a cast: This will be an issue for groovyc as well wherever GROOVY-10049 is addressed. |
Here are forms that should work the same; @groovy.transform.TypeChecked
void test() {
Object v1 = 'a'
Object v2 = 'b'
[v1, v2].each { v ->
if (v instanceof Map) {
v.each { e ->
def s = e.value
if (s instanceof String)
e.value = s.toUpperCase()
}
}
}
} STC should infer
|
ready to test |
Version 4.3.0.v202107240018-e2009 fixes the problem for me, thank you! |
In this specific case, it can be determined that the only possible type for "v" is String. So an "instanceof Map" check presents an inconvertible type and so Map is ignored. You can add a typecast to the list: |
Still, it's unexpected that static type inference and dynamic type inference behave in different ways in this example... |
Consider this:
An error is given on both occurrences of
e.value
, becausee
is evaluated asObject
instead ofMap.Entry
.This used to work until some version of the Greclipse plugin (now I'm on 4.3.0.v202107132103-e2009).
If I compile this with Gradle/Groovy, the JAR is built successfully.
If I remove
@CompileStatic
, I get underlining forv.entrySet()
and again on both occurrences ofe.value
.If I try to give
e
a type in the closure:I see this:
@CompileStatic
an additional error is given onEntry
, saying it's expectingObject
.@CompileStatic
, instead, the underlining fore.value
is fixed, so the situation improves.The text was updated successfully, but these errors were encountered: