Skip to content

Static type checking fails in Greclipse within closure (closure declared argument types ignored) #1327

@mauromol

Description

@mauromol

Using Greclipse 4.4.0.v202112282355-e2009.

Consider this Java utility class:

package test70;
import java.util.List;
import java.util.function.BiConsumer;

public class Util {
	public static <T> BiConsumer<String, ? super List<T>> batchFromIndividualPostProcessor(
			final BiConsumer<String, ? super T> postProcessor) {
		return (text, batch) -> {
			for (final T element : batch)
				postProcessor.accept(text, element);
		};
	}
}

and this Groovy class:

package test70
import groovy.transform.CompileStatic

@CompileStatic
class Test70 {
	void foo() {
		Util.batchFromIndividualPostProcessor { String text, Number number ->
			number.toBigDecimal()
		}
	}
}

A compilation error is produced on number.toBigDecimal() because number is detected as Object rather than Number.

Please note that:

  • this was compiling fine with some versions of Greclipse ago (cannot say exactly which one now)
  • this compiles fine with Gradle/groovyc
  • switching to @CompileDynamic makes things work

I have other more complex use cases in my real-world project which I think are related to this same problem. It seems like Greclipse is simply ignoring now the type I'm declaring for closure arguments.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions