codeconsole opened a new pull request, #3289: URL: https://github.com/apache/groovy/pull/3289
https://issues.apache.org/jira/browse/GROOVY-12756 Anything can be assigned to a `Class`, `String` or `Boolean` variable: the value is converted at run time, so `Class c = 'java.lang.String'` loads the class. Since GROOVY-12714, static type checking rejects that when the variable's type has a type argument, even `Class<?>`, while the same assignment to a raw `Class` still compiles: ```groovy Class raw = type // compiles Class<?> any = type // a java.lang.reflect.Type: error Class<String> string = 'java.lang.String' // error Class<? extends Number> number = object // an Object: error ``` ``` [Static type checking] - Incompatible generic argument types. Cannot assign java.lang.reflect.Type to: java.lang.Class<?> ``` Grails no longer compiles against GROOVY_6_0_X because of this: `AbstractStructuredBindingEditor` assigns `actualTypeArguments[0]`, a `Type`, to its `Class<T> targetType`. For such a variable `getResultType` returned the variable's type. GROOVY-12714 made it keep the type of the value when the variable is a parameterized `Class`, so that `Class<?>` is not accepted for `Class<? extends CharSequence>`. When the value is not a `Class` there are no type arguments to compare, and `checkTypeGenerics` reported the value's type as an incompatible generic argument. The type of the value is now kept only when it is a `Class`, so a `Class` value is still checked against the type arguments. `STCAssignmentTest`, and so `AssignmentsStaticCompileTest`, gets the three forms and the `Class<?>` to `Class<? extends CharSequence>` case that must stay an error. The test fails without the change. Please also apply this to GROOVY_6_0_X, where the change applies cleanly. -- 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]
