Details
-
Bug
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.0.6
-
None
-
None
Description
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.
@CompileStatic Number returnANumber() { Number number = Optional.of(1234 as Integer) // should infer Optional<Number> orElse(42.0 as Double) }
[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.
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.