Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
4.0.17
-
None
Description
While working with Micronaut, I encountered a problem related to Groovy STC. I think the following code should compile, but it fails at line 13 with
[Static type checking] - Cannot find matching method B#intValue(). Please check if the declared type is correct and if the method exists. at line: 13, column: 27
There is a simple workaround, as demonstrated in printOptionalSecondTry(), that compiles correctly.
@Grab(group='io.micronaut', module='micronaut-http', version='4.2.2') import groovy.transform.CompileStatic import io.micronaut.http.HttpResponseFactory import io.micronaut.http.HttpResponse @CompileStatic class MyClass { static <T> HttpResponse<T> fetchMeHttpResponse(T value) { return HttpResponseFactory.INSTANCE.ok(value) as HttpResponse<T> } static printOptional() { Integer myValue = fetchMeHttpResponse(10G).body.orElseThrow(() -> new RuntimeException("blah blah")).intValue() println myValue } static printOptionalSecondTry() { BigInteger myOptionalValue = fetchMeHttpResponse(10G).body.orElseThrow(() -> new RuntimeException("blah blah")) Integer myValue = myOptionalValue.intValue() println myValue } } MyClass.printOptional() MyClass.printOptionalSecondTry()
Attachments
Attachments
Issue Links
- relates to
-
GROOVY-11266 Static Compilation fails when using generics (no such property)
- Closed