codeconsole opened a new pull request, #3286: URL: https://github.com/apache/groovy/pull/3286
https://issues.apache.org/jira/browse/GROOVY-12755 Stacked on #3285 (GROOVY-12754). Only the last commit is new here. Since GROOVY-12714, static type checking rejects `x.getClass()` where a `Class<? extends T>` is expected, because it types the call as `Class<?>`, the declared return type of `Object#getClass()`. javac types it as `Class<? extends |T|>` (JLS 4.3.2), the erasure of the receiver's static type. Grails no longer compiles against GROOVY_6_0_X because of this, for example: ```groovy // withTenant(Class<? extends Datastore> datastoreClass, Serializable tenantId, Closure<T> callable) CurrentTenantHolder.withTenant(datastore.getClass(), tenantId) { ... } ``` `inferReturnTypeGenerics` now types `e.getClass()`, and so `e.class`, as `Class<? extends |T|>`: a type variable becomes its bound, type arguments are dropped, an array keeps its dimensions, and a primitive receiver is boxed. The bound is a raw type, as if written in source. That makes more calls pass a `Class<? extends X>` to a bounded `<T extends B> m(Class<T>)`, which GROOVY-12754 fixes. Without it, `foo(l.class, l)` in `testMethodLevelGenericsForMethodCall` fails. Two existing expectations change. The inferred type of `list.class` for a raw `List`, in `FieldsAndPropertiesSTCTest`, is now `Class<? extends java.util.List>` rather than `Class<? extends java.lang.Object>`. The GROOVY-5415 message now names `Class<? extends ClassB>`. `GenericsJavaCompatibilityTest` checks against javac: passing, returning and assigning a `getClass()` result, with a type variable, a raw type and an array, plus a negative case for an `Object` receiver. `GenericsSTCTest` covers the Groovy forms: `.class`, an implicit `this`, a closure, a static context, a primitive, arrays and a type variable. They fail without the change. Please also apply this to GROOVY_6_0_X, after GROOVY-12754. Both cherry-pick cleanly, and with them the four Grails modules that fail compile against the branch. -- 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]
