You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2023/12/24 11:33:00 UTC
[jira] [Updated] (GROOVY-11257) [STC] Cannot detect the type of Optional in some cases
[ https://issues.apache.org/jira/browse/GROOVY-11257?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-11257:
---------------------------------
Fix Version/s: 4.0.18
> [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: 4.0.18, 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)