Skip to content

Type inferencing error (only in Eclipse, not in groovyc) #1281

@mauromol

Description

@mauromol

Consider this:

package test70

import groovy.transform.CompileStatic

@CompileStatic
class Test70 {

	void foo() {
		Object v1 = 'a'
		Object v2 = 'b'
		[v1, v2].each {
			v ->
			if(v instanceof Map) {
				v.entrySet().each { e ->
					def s = e.value
					if(s instanceof String)
					e.value = s.toUpperCase()
				}
			}
		}
	}
}

An error is given on both occurrences of e.value, because e is evaluated as Object instead of Map.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 for v.entrySet() and again on both occurrences of e.value.

If I try to give e a type in the closure:

				v.entrySet().each { Entry e ->
					def s = e.value
					if(s instanceof String)
					e.value = s.toUpperCase()
				}

I see this:

  • with @CompileStatic an additional error is given on Entry, saying it's expecting Object.
  • without @CompileStatic, instead, the underlining for e.value is fixed, so the situation improves.

image

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions