paulk-asert opened a new pull request, #3313:
URL: https://github.com/apache/groovy/pull/3313

   This fixes the regressions reported against `GROOVY_6_0_X` since 
GROOVY-12714, and nothing else. It is for 6.0.1 only. #3293 remains the 
proposal for master.
   
   The aim is narrow: a program that 6.0.0 compiled, and that GROOVY-12714 did 
not set out to reject, compiles again. No rule of GROOVY-12714 is relaxed, and 
no check is added beyond it.
   
   ## Commits
   
   - **GROOVY-12756** (Scott, the first commit of #3289). A value that is not a 
`Class` may be assigned to a parameterized `Class` variable again: 
`Class<String> c = 'java.lang.String'`, and `targetType = types[0]` in Grails' 
`AbstractStructuredBindingEditor`.
   - **GROOVY-12757**. The type parameters of a method and of its receiver are 
substituted in one pass, so a lambda result that names the caller's `T` no 
longer takes the receiver's `T`. This is the fix from #3293, with Scott's tests 
from #3290.
   - **GROOVY-12755**. Two changes, described below.
   
   ## GROOVY-12755
   
   **`getClass()` for a bounded `Class`.** `x.getClass()` and `x.class` keep 
the type `Class<?>`, as in 6.0.0. They are accepted for a `Class<? extends T>` 
variable, return type or parameter when the type of `x` is within `T`, 
including a type given by `instanceof`:
   
   ```groovy
   static <T> T with(Class<? extends Store> type, Closure<T> body) { 
body.call() }
   static Object m(Store store) { with(store.getClass()) { 1 } }
   static Class<? extends Store> type(Store store) { store.getClass() }
   ```
   
   A `Class<?>` from anywhere else is still rejected for a bounded `Class`, and 
so is `o.getClass()` for an `Object o`.
   
   This differs from #3286, which types `getClass()` as `Class<? extends |T|>`. 
That is the better long-term answer, but it changes the type of every list 
built from `getClass()`, so code such as `List<Class<?>> l = list*.getClass()` 
stops compiling unless target typing is added as well. Keeping the declared 
type avoids that in a patch release.
   
   **A type parameter that a call left open.** A type variable in the result of 
a generic call that is declared neither by the enclosing method nor by an 
enclosing class was left open by the call's arguments. It is not checked 
against the target, and takes its type from it, as before GROOVY-12714. That 
restores, for example:
   
   ```groovy
   Consumer<Integer> c = toConsumer(C::takeNumber)
   Function<Object[], List<Object>> f = toFunction(Arrays::asList)
   Comparator<Map.Entry<String, Integer>> byKey = Map.Entry.comparingByKey()
   ```
   
   A type variable that is in scope is still checked, as GROOVY-12714 
introduced.
   
   ## Not included
   
   - **GROOVY-12754.** 6.0.0 and 5.1.3 reject its legal cases too, so it is not 
a regression. It is only needed with the `getClass()` typing of #3286.
   - **The later commits of #3289.** A field initializer, a property write and 
a map write of a value that is not a `Class` were compile errors in 6.0.0 and 
still are.
   - **Target typing and the method reference checks of #3293.** A method 
reference whose type parameter is outside its bound, such as `Consumer<String> 
c = toConsumer(C::takeNumber)`, compiles as it does in 6.0.0.
   - **`COMPATIBILITY.md`.** GROOVY-12714 itself has no entry on this branch 
yet; that should be added separately.
   
   ## Known limits
   
   - Whether a type variable is in scope is decided by name. If the enclosing 
method declares a `T` and a called method leaves its own `T` open, the check 
still applies.
   - `Class<T> c = t.getClass()` for a type variable `T` compiles, as in 6.0.0.
   
   ## Testing
   
   - The root test suite passes (19,736 tests).
   - 144 small programs (the ticket reproducers, the examples from #3293 and 
its review, and probes for each rule of GROOVY-12714) give the same result as 
6.0.0 and 5.1.3, except where GROOVY-12714 rejects them.
   - Grails `9.0.x` compiles against this branch (`compileGroovy` and 
`compileTestGroovy`), including `grails-web-databinding` and `grails-async`. 
One test example fails, 
`spring-security/ldap/custom-user-details-context-mapper`: it passes a 
`Collection<? extends GrantedAuthority>` to a `Collection<GrantedAuthority>` 
parameter, which is a rule GROOVY-12714 states and this branch keeps.
   - None of the 144 programs changes in 6.0.1 and changes back with #3293 on 
master.


-- 
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