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

Daniel Sun reassigned GROOVY-11446:
-----------------------------------

    Assignee: Daniel Sun

> Missing type mismatch when dealing with a polymorphic function expecting a 
> wildcard
> -----------------------------------------------------------------------------------
>
>                 Key: GROOVY-11446
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11446
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static Type Checker
>            Reporter: Thodoris Sotiropoulos
>            Assignee: Daniel Sun
>            Priority: Minor
>
> I have the following program
> {code:java}
> class Test {
>   public static void main(String[] args) {
>     List<?> d = ["fda"];
>     List<Number>  x = m(d);
>     x[0].intValue();
>   }
>   public static <T> List<T> m(List<? extends T> x) { return x }
> } {code}
> h3. Actual behavior
> The code compiles, but when running the program I receive the following 
> exception
>  
> {code:java}
> Exception in thread "main" java.lang.ClassCastException: class 
> java.lang.String cannot be cast to class java.lang.Number (java.lang.String 
> and java.lang.Number are in module java.base of loader 'bootstrap')
>     at Test.main(test.groovy:5) {code}
> h3. Expected behavior
> The code should have been rejected, as the return type of method `m()` is 
> List<?>, which is incompatible with the expected type List<Number>
> h3. Notes
> Notably, when changing the signature of method m as
> {code:java}
> public static <T> List<T> m(List<T> x) { return null; } {code}
> the code is rejected as expected.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to