[ https://issues.apache.org/jira/browse/GROOVY-11364?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles updated GROOVY-11364: --------------------------------- Fix Version/s: 3.0.22 > STC loses generic specialization on inheritance > ----------------------------------------------- > > Key: GROOVY-11364 > URL: https://issues.apache.org/jira/browse/GROOVY-11364 > Project: Groovy > Issue Type: Bug > Components: Static Type Checker > Affects Versions: 4.0.15, 4.0.21 > Reporter: Christopher Smith > Assignee: Eric Milles > Priority: Major > Fix For: 3.0.22, 5.0.0-alpha-9, 4.0.22 > > > When a base class contains a type parameter {{<N>}} and a method returns > {{N}}, the STC believes that the return type is the superclass bound of {{N}} > and not the actual type of {{N}}. Overriding the method in the subclass with > the specific type does not fix the problem. > {code:groovy} > package bug.groovy > import groovy.transform.CompileStatic > @CompileStatic > abstract class BugRepro<N extends Number> { > protected N process(N input) { input } > } > @CompileStatic > class IntegerRepro extends BugRepro<Integer> { > static void consume(Optional<Integer> input) {} > // The compilation fails with or without this override > @Override > protected Integer process(Integer input) { super.process(input) } > void run() { > consume(Optional.of(42).map(this::process)) > } > } > {code} > Error: > {code} > Groovy:[Static type checking] - Cannot call > bug.groovy.IntegerRepro#consume(java.util.Optional<java.lang.Integer>) with > arguments [java.util.Optional<java.lang.Number>] > {code} > Expected: The compiler recognizes that {{N}} at the call site is {{Integer}}. > This bug appears to have been introduced in 4.0.15; the code compiles > correctly in 4.0.14. The bug is still present in 4.0.21. -- This message was sent by Atlassian Jira (v8.20.10#820010)