daniellansun commented on PR #2845:
URL: https://github.com/apache/groovy/pull/2845#issuecomment-5479443071

   @paulk-asert  Thanks, Paul — this was the right list to walk through before 
merge. We have decided each row as below; the well-formedness checks stay on 
**every** compilation unit (dynamic Groovy and scripts included), with no 
opt-out.
   
   ### Team call 1 — `new T[n]` / `new T[]{…}`
   
   We will **reject** it, with no carve-out in `isReifiable`.
   
   A type variable is not reifiable (JLS 4.7 / 15.10.1). What Groovy 4/5 
compiled was `Object[]` (or the bound) typed as `T[]` — Java’s `(T[]) new 
Object[n]`, without the cast in the source. Treating `T` as reifiable would 
also be the wrong predicate for `instanceof T`.
   
   The Java idiom remains the workaround, in both dynamic and `@CompileStatic` 
code:
   
   ```groovy
   items = (T[]) new Object[capacity]          // unbounded T
   items = (T[]) new Bound[capacity]           // T extends Bound
   items = (T[]) Array.newInstance(token, n)   // when a Class<T> is at hand
   ```
   
   `new List<String>[n]` stays rejected; `new List<?>[n]` stays legal.
   
   ### Team call 2 — generic class extending `Throwable`
   
   We will **reject** it as well, for JLS 8.1.2 / javac parity. Groovy’s 
`catch` is erased, so the class would still run on the JVM — but this PR’s 
charter is well-formedness that javac already enforces, and Groovy 6 is the 
window.
   
   Workaround: keep the exception non-generic and move the type parameter onto 
an accessor (or a factory). Parameterized `catch` is already impossible in the 
grammar (`catchType` has no type arguments).
   
   ### Remaining rows
   
   Agreed: **break and document** for all of them, including `List<int>`, `new 
T()` / `T.class`, `implements X<? extends …>`, `new ArrayList<?>()` , a class 
type as an additional bound, `Foo<String>.class`, and `Outer.Inner<String>` 
with a raw generic `Outer`.
   
   A table in that shape is now in `core-object-orientation.adoc` §Generics 
(`[[generics-well-formedness]]`), with the two workarounds above as executable 
examples. I would still welcome a matching table in the 6.0 release notes if 
you would like to take that, as you offered.
   
   ### Message nits
   
   Both fixed:
   
   - `new T[n]` now reports `generic array creation of T` (the type variable, 
not the erasure).
   - `Foo<String>.class` now reports `Cannot select from a parameterized type` 
(JLS 15.8.2). `Cell<String>.ID` / `.id()` keep the 4.5.2 “static member through 
a parameterization” wording. `value.class` / `value*.class` are unchanged — 
those are `getClass()`, not class literals.
   
   ### `"outer.class"` metadata
   
   Noted. The enclosing type lives on the `ClassNode` field 
(`getOuterClassType()` / `@since 6.0.0`); we will not restore a metadata 
fallback. Transform authors who still read the GROOVY-10646-era key will see 
`null`.
   


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