[ 
https://issues.apache.org/jira/browse/GROOVY-12724?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18144451#comment-18144451
 ] 

ASF GitHub Bot commented on GROOVY-12724:
-----------------------------------------

daniellansun commented on code in PR #3259:
URL: https://github.com/apache/groovy/pull/3259#discussion_r4564421790


##########
src/main/java/org/codehaus/groovy/control/ResolveVisitor.java:
##########
@@ -582,9 +590,41 @@ protected boolean resolve(final ClassNode type, final 
boolean testModuleImports,
         if (resolved && genericsTypes != null) {
             resolveWildcardBounding(genericsTypes, type);
         }
+        if (resolved) {
+            normalizeUseSite(type);
+        }
         return resolved;
     }
 
+    /**
+     * Drops type arguments a class does not declare and boxes a primitive
+     * argument or wildcard bound. A use site is a redirect; the declaration
+     * itself is left alone. An unresolved name is not a redirect yet, so this
+     * runs again once {@link #resolve} has found the class.
+     */
+    private static void normalizeUseSite(final ClassNode type) {
+        if (type == null || type.isGenericsPlaceHolder() || 
!type.isRedirectNode()) {
+            return;
+        }
+        GenericsType[] arguments = type.getGenericsTypes();
+        if (arguments == null || arguments.length == 0) {
+            return;
+        }
+        GenericsType[] legal = GenericsUtils.legalTypeArguments(type, 
arguments);
+        if (legal == arguments) {
+            return;
+        }
+        if (legal == null || legal.length == 0) {
+            type.setGenericsTypes(null);
+            ClassNode outer = type.getOuterClassType();

Review Comment:
   Thanks for the question. On the current tip (c56d922c), a source use site 
such as `String<Integer>` is a compile error again, the same as in 6.0.0:
   
   ```
   The class java.lang.String<java.lang.Integer> (supplied with 1 type 
parameter) refers to the class java.lang.String which takes no parameters
   ```
   
   The revision you commented on dropped type arguments in `ResolveVisitor` 
when the class declares no type parameters, so `String<Integer>` would have 
compiled as a raw `String`. That was a mistake on my side, and c56d922c removes 
the rewriting. The arguments now reach `GenericsVisitor`, which rejects a use 
site that is not a well-formed parameterized type (JLS 4.5: it is an error if 
the class is not generic or the number of type arguments differs from its type 
parameters). `ClosureReturnTypeSignatureTest.nonGenericUseSiteIsRejected` 
covers this for `java.io.Serializable` and for a source class.
   





> GINQ: support static compilation and a fluent query API
> -------------------------------------------------------
>
>                 Key: GROOVY-12724
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12724
>             Project: Groovy
>          Issue Type: Improvement
>          Components: GINQ
>            Reporter: Daniel Sun
>            Assignee: Daniel Sun
>            Priority: Major
>
> Under @CompileStatic / @TypeChecked, GQ, GQL, and @GQ currently rely on 
> dynamic lowering. This improvement makes those entry points usable from a 
> statically checked scope while keeping the SQL-like syntax lowered to the 
> in-memory collection runtime.
> h3. Goals
> * Allow GQ / GQL / @GQ from @CompileStatic and @TypeChecked without forcing 
> the lowered tree through static checking at the expression site.
> * Defer pipeline construction with LazyQueryable until a terminal read 
> (toList, count, etc.), copying locals at the expression site (same binding as 
> dynamic GQ).
> * Add Ginq.from(...) as a deferred, generic fluent chain on the same runtime, 
> with @ClosureParams so where/select/join/aggregate closures can infer element 
> types where inference is sound.
> * Preserve default lazy/deferred evaluation and dynamic GQ behavior for map 
> rows and other intentionally dynamic cases.
> h3. Non-goals / known limits
> * Stored untyped Closure variables still need a SAM target type for parameter 
> inference (same as Java/C#).
> * Raw Query parameters/fields cannot recover a safe element type.
> * Names bound by from inside GQ / GQL / @GQ stay dynamic by design; callers 
> that need checked element types use Ginq.from.
> h3. Related work
> GitHub PR: https://github.com/apache/groovy/pull/3259
> Stacked on GEP-26 SQL window work (PR #3167 / gep26-sql-window).



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to