codeconsole opened a new pull request, #3285:
URL: https://github.com/apache/groovy/pull/3285

   https://issues.apache.org/jira/browse/GROOVY-12754
   
   `compatibleConnection` checked an upper-bounded wildcard argument against 
the bound of a method's type parameter the wrong way round, asking whether the 
bound fits within `? extends B`. So static type checking rejected calls that 
javac accepts:
   
   ```groovy
   static <T extends Number> T first(List<T> list) { list.get(0) }
   static <T extends CharSequence> int len(Class<T> type) { 0 }
   
   static Object a(List<? extends Integer> ints) { first(ints) }
   static int b(Class<? extends String> type) { len(type) }
   ```
   
   And it accepted one that javac rejects, `narrow(List<? extends Number>)` for 
`<T extends Integer> T narrow(List<T>)`, where the statically compiled call 
then returned `1` for `1.5`.
   
   The capture of `? extends B` is a subtype of `B` (JLS 5.1.10), so the 
wildcard is now checked as a type argument `B` is, by testing `? super B` 
against the bound. An unbounded wildcard, one bounded by `Object` or by a type 
variable, and a lower-bounded one keep the existing path. Code like `narrow` 
above, which compiled before, is now rejected, as javac rejects it.
   
   `GenericsJavaCompatibilityTest` gets a positive and a negative case checked 
against javac. `GenericsSTCTest`, and so `GenericsStaticCompileTest`, gets the 
Groovy forms, including a `Class<? extends ArrayList>` for `<T extends 
List<Integer>>`. All of them fail without the change.
   
   Please also apply this to GROOVY_6_0_X, where it cherry-picks cleanly. 
GROOVY-12755 depends on it.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to