daniellansun opened a new pull request, #3381: URL: https://github.com/apache/groovy/pull/3381
This PR fixes a set of generics type-checking bugs in `@TypeChecked` and `@CompileStatic` covering member resolution, `instanceof Class` narrowing, rigid type variables, explicit and LUB-widened method type arguments, diamond constructors, open generic calls, dynamic method references, and PECS wildcard rules. The changes are split into 8 commits by topic, with each JIRA issue resolved in a single commit. ### Commits - `a1669dd` **GROOVY-12771**: Resolve unqualified inherited member class names inside nested classes in `ResolveVisitor` by walking enclosing classes and their superclass hierarchies (JLS §6.5.5.1). - `e1b2376` **GROOVY-12770**: Narrow `instanceof Class` (including negated guards and `switch` cases) to `Class<?>` instead of raw `Class`. - `d737e11` **GROOVY-12769, GROOVY-12772, GROOVY-12773, GROOVY-12774, GROOVY-12775** (also resolves GROOVY-7719, GROOVY-7720, GROOVY-10625, GROOVY-10977): Treat in-scope enclosing type variables as rigid targets, check non-generic subclasses of parameterized types against wildcard bounds through their supertypes, reject raw wildcard bounds passed to parameterized receivers, and resolve inherited/inner generic fields against concrete enclosing type arguments. - `413dd5f` **GROOVY-12766, GROOVY-11047**: Check explicit method/constructor type argument counts, bounds (including zero-arg/varargs calls and SAM parameters), and arguments; re-check bounds and all arguments when LUB widens an inferred type parameter; check initializer-narrowed locals consistently under `@TypeChecked` and `@CompileStatic`. - `252cbbe` **GROOVY-12765**: Validate diamond constructor arguments against target-supplied type arguments across assignments, returns, closure/lambda returns, conditionals, and method arguments. - `05c62ce` **GROOVY-12776, GROOVY-12777, GROOVY-12778, GROOVY-12779, GROOVY-12780** (also resolves GROOVY-10120, GROOVY-10257, GROOVY-11446): Unify target typing via `resolveAgainstTargetType` and `isApplicableForTargetType`; check constructor/method references, closures, lambdas, and value arguments in open generic calls against SAM parameters and declared bounds (including self-referential bounds like `<T extends Comparable<T>>`); retry overloaded extension method references with the enclosing call's target SAM types (`List::join`); preserve receiver type parameters for unbound `Type::instanceMethod` references (`Comparator.comparing(Map.Entry::getKey)`); erase raw SAM types in `GenericsUtils.parameterizeSAM` (JLS §4.8). - `831240b` **GROOVY-12781**: Keep compile-time overload selection for `::` under `@CompileStatic` (matching Java) while checking all runtime-selectable overloads (`findSelectableMethods`) for dynamically dispatched `::` under `@TypeChecked` and `.&`. Reject calls with no selectable overload (except when deferred for an open enclosing generic call) and require every selectable overload to match the SAM return type. - `076e26f` **GROOVY-12714**: Enforce PECS wildcard containment and capture conversion (JLS §4.5.1, §5.1.10) in `GenericsType`, `StaticTypeCheckingSupport`, `StaticTypeCheckingVisitor`, and `ClassTagSupport`: reject producer wildcards (`? extends ...`, `?`) in consumer (`? super T`) positions, preserve unbounded `?` instead of erasing to `Object` on mutating calls, prevent distinct wildcards from unifying for invariant parameters, check writes to generic fields/properties on wildcard receivers under capture conversion, handle `? super T` / `? extends T` and F-bounded self-type containment, and reject unresolved wildcards in `ClassTag.of(...)`. ### Compatibility & Docs - Statically checked code that relied on unchecked diamond/method-call widening, PECS-violating wildcard writes or producer-as-consumer calls, unchecked `instanceof Class` narrowing, or dynamically dispatched method references/pointers with incompatible narrower overloads will now fail at compile time instead of failing at runtime. - Dynamic Groovy, raw-type unchecked conversions (outside wildcard bounds), raw-type member erasure, and overload-selection-before-generics-checking precedence are unchanged. - Updated `COMPATIBILITY.md`, `src/spec/doc/core-operators.adoc`, and `src/spec/doc/core-semantics.adoc` (with executable spec tests in `OperatorsTest`, `StaticCompilationIntroTest`, and `TypeCheckingTest`). ### Verification - Compiled and ran the targeted unit, regression, compatibility, and spec test suites on each commit individually (`GenericsSTCTest`, `GenericsJavaCompatibilityTest`, `FunctionalTargetTypingSTCTest`, `MethodReferenceTest`, `ClassTagStaticTest`, `GenericsUtilsTest`, `STCAssignmentTest`, `RegressionTest`, and updated spec tests). - Verified `./gradlew :checkGroovyABISync :lintGate` passes 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]
