[ 
https://issues.apache.org/jira/browse/GROOVY-9796?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Milles updated GROOVY-9796:
--------------------------------
    Attachment: screenshot-1.png

> Static type checker doesn't backtrack when solving generics
> -----------------------------------------------------------
>
>                 Key: GROOVY-9796
>                 URL: https://issues.apache.org/jira/browse/GROOVY-9796
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>    Affects Versions: 3.0.6
>            Reporter: Christopher Smith
>            Assignee: Eric Milles
>            Priority: Major
>         Attachments: screenshot-1.png
>
>
> When a method pipeline involves generics, the static type checker is greedy 
> and tends to be overly specific, producing errors when the correct answer 
> involves relaxing to a common bound.
> {code:groovy}
> @CompileStatic
> Number returnANumber() {
>   Number number = Optional.of(1234 as Integer) // should infer 
> Optional<Number>
>     orElse(42.0 as Double)
> }
> {code}
> {code}
> [Static type checking] - Cannot find matching method 
> java.util.Optional#orElse(java.lang.Double). Please check if the declared 
> type is correct and if the method exists.
> {code}
> Explicitly inserting a type witness {{Optional.<Number>of}} works.
> Note: This _might_ be a duplicate of GROOVY-8103, but I'm unable to tell 
> precisely. 3.0.6 was released one week after it was marked resolved. 
> GROOVY-8961 is marked fixed in 3.0.6, but I'm having the problem there.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to