[ https://issues.apache.org/jira/browse/GROOVY-11257?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles resolved GROOVY-11257. ---------------------------------- Fix Version/s: 5.0.0-alpha-5 Resolution: Fixed https://github.com/apache/groovy/commit/f72ec8ba53b0b645a1044c033752f903c9ce84d3 > [STC] Cannot detect the type of Optional in some cases > ------------------------------------------------------ > > Key: GROOVY-11257 > URL: https://issues.apache.org/jira/browse/GROOVY-11257 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker > Affects Versions: 4.0.17 > Reporter: Damir Murat > Assignee: Eric Milles > Priority: Major > Fix For: 5.0.0-alpha-5 > > > 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 > {code:java} > [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{code} > There is a simple workaround, as demonstrated in printOptionalSecondTry(), > that compiles correctly. > {code:java} > @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() > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)