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

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

testlens-app[bot] commented on PR #2845:
URL: https://github.com/apache/groovy/pull/2845#issuecomment-5479663588

   ## 🚨 TestLens detected 1 failed test 🚨
   
   Here is what you can do:
   
   1) Inspect the test failures carefully.
   2) If you are convinced that some of the tests are flaky, you can mute them 
below.
   3) Finally, trigger a rerun by checking the rerun checkbox.
   
   ### Test Summary
   
   #### [Build and test / lts \(17, 
macos-latest\)](https://github.com/apache/groovy/actions/runs/33399690581/job/99512674719?pr=2845)
 > :test
   
   | Test | Runs | Flakiness |
   |---|---|--:|
   | MethodReferenceTest > testFunctionCI\_DGM2\(\) | ❌ | 0% 🟢 |
   
   🏷️ Commit: 1eea44ba3ea1a0afc91b7850a9bf7e62aa5f9276
   ▶️ Tests:  11428 executed
   🟡 Checks: 17/29 completed
   
   ### Test Failures
   
   <details>
   
   <summary><strong>MethodReferenceTest > testFunctionCI_DGM2()</strong> (:test 
in <a 
href="https://github.com/apache/groovy/actions/runs/33399690581/job/99512674719?pr=2845";>Build
 and test / lts (17, macos-latest)</a>)</summary>
   
   ```
   org.codehaus.groovy.control.MultipleCompilationErrorsException: startup 
failed:
   TestScript102.groovy: 11: Cannot select from a parameterized type
    @ line 11, column 49.
                  def optional = 
Optional.empty().map(Iterable<String>::asCollection)
                                                      ^
   
   1 error
   
        at 
org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:333)
        at 
org.codehaus.groovy.control.CompilationUnit$IPrimaryClassNodeOperation.doPhaseOperation(CompilationUnit.java:1136)
        at 
org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:762)
        at 
org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:736)
        at 
groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:436)
        at 
groovy.lang.GroovyClassLoader.lambda$parseClass$3(GroovyClassLoader.java:377)
        at 
org.codehaus.groovy.runtime.memoize.ConcurrentCommonCache.getAndPut(ConcurrentCommonCache.java:143)
        at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:377)
        at groovy.lang.GroovyShell.parseClass(GroovyShell.java:664)
        at groovy.lang.GroovyShell.parse(GroovyShell.java:677)
        at groovy.lang.GroovyShell.parse(GroovyShell.java:689)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:551)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:587)
        at groovy.lang.GroovyShell.evaluate(GroovyShell.java:571)
        at groovy.test.GroovyAssert.assertScript(GroovyAssert.java:106)
        at 
groovy.transform.stc.MethodReferenceTest.testFunctionCI_DGM2(MethodReferenceTest.groovy:1517)
   ```
   
   </details>
   
   ### Rerun Controls
   > [!NOTE]
   > Checks are currently running using the configuration below.
   
   Select tests to mute in this pull request:
   
   🔲 MethodReferenceTest > testFunctionCI\_DGM2\(\) <!

> Java compatibility: remaining generic type syntax
> -------------------------------------------------
>
>                 Key: GROOVY-12319
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12319
>             Project: Groovy
>          Issue Type: Improvement
>            Reporter: Daniel Sun
>            Priority: Major
>
> Groovy already accepts most Java generics. Three Java forms still fail: two 
> in the parser, one in {{GenericsVisitor}}. Each has a local workaround.
> Method type arguments such as {{Helper.<String>identity( x )}} already work 
> and are not part of this request.
> h3. 1. Diamond {{<>}} on an anonymous class
> Java 9+ (JEP 213, JLS 15.9.5) allows diamond when creating an anonymous 
> class, if the target type supplies the type arguments:
> {code:java}
> Processor<String> p = new Processor<>() {
>     public String process(String val) { return val.toUpperCase(); }
> };
> {code}
> This should work in assignment, as a method argument, and under 
> {{@TypeChecked}} / {{@CompileStatic}}, for both interfaces and abstract 
> classes.
> *Actual:* Groovy rejects it with {{Cannot use diamond <> with anonymous inner 
> classes}}.
> *Workaround:* write the type arguments explicitly:
> {code:java}
> Processor<String> p = new Processor<String>() {
>     public String process(String val) { return val.toUpperCase(); }
> };
> {code}
> GROOVY-6730 and GROOVY-7159 were false-positive STC errors when diamond was 
> _not_ used. They did not add this form.
> h3. 2. Qualified parameterized inner types ("rare" types)
> Java allows an inner type to keep the enclosing type's arguments (JLS 4.5):
> {code:java}
> class Outer<T> {
>     class Inner<U> {}
> }
> Outer<String>.Inner<Integer> x = new Outer<String>().new Inner<Integer>("v", 
> 1);
> {code}
> The same qualification appears as a field or method type, nested in another 
> type argument, as a superclass when the member is a non-static class, and in 
> a qualified instance creation inside the outer class:
> {code:java}
> List<Outer<String>.Inner<Integer>> list;
> class Sub extends Outer<String>.Inner {
>     Sub(Outer<String> o) { o.super(); }
> }
> // inside Outer:
> new Outer<T>.Inner<U>(...)
> {code}
> Selecting a static member type from a parameterization is a compile-time 
> error (JLS 4.5.2 / 6.5.5). Nested interfaces and enums are implicitly static 
> (JLS 9.5), so a nested interface must be selected from the raw enclosing name:
> {code:java}
> class Impl implements Outer.Inner<Integer> { ... }           // legal
> class Bad  implements Outer<String>.Inner<Integer> { ... }   // error
> {code}
> *Actual:* Groovy fails to parse {{Outer<String>.Inner}} ({{Unexpected 
> input}}).
> *Workaround:* a factory that returns {{Inner}} without naming 
> {{Outer<T>.Inner}}.
> h3. 3. Explicit type arguments on constructors, {{this()}} and {{super()}}
> Java allows constructor type arguments independently of the class type 
> arguments (JLS 15.9 / 8.8.7.1):
> {code:java}
> class Box {
>     <T> Box(T t) {}
>     Box() { <String>this("x"); }
> }
> class Derived extends Box {
>     Derived() { <String>super("y"); }
> }
> class Outer {
>     class Inner {
>         <T> Inner(T t) {}
>     }
> }
> new <String>Box("x");
> new Outer().new <String>Inner("z");
> {code}
> *Actual:* Groovy fails at {{new <}} with {{Unexpected input: '<'}}.
> *Workaround:* inference, e.g. {{new Box("x")}}.
> Constructor type arguments are already tracked by GROOVY-10501. The 
> {{this()}} / {{super()}} / inner-{{new}} forms are the same JLS production 
> and should be handled together.
> h3. Expected
> All three forms compile in dynamic Groovy and under {{@TypeChecked}} / 
> {{@CompileStatic}}, matching javac on well-formed programs.
> The well-formedness rules are javac's (checked against javac 25). Parsing a 
> rare type does not make every use of it legal.
> These remain legal. {{Inner}} is a non-static member of {{Outer}}; 
> {{Outer<?>}} is reifiable (JLS 4.7), so a non-static member type of that 
> enclosing type is reifiable (JLS 15.10.1):
> {code:java}
> class Outer<T> {
>     class Inner {}
>     class InnerG<U> {}
>     interface Iface<U> { U id(U u); }
> }
> Outer<?>.Inner[] a = new Outer<?>.Inner[0];
> Outer<?>.InnerG<?>[] b = new Outer<?>.InnerG<?>[0];
> Outer<?>.Inner field;
> Outer<String>.Inner concrete;
> class Impl implements Outer.Iface<Integer> {
>     public Integer id(Integer u) { return u; }
> }
> {code}
> These remain compile errors:
> {code:java}
> new Object<>() {}                          // diamond on a non-generic type
> class C extends ArrayList<> {}             // diamond on a class declaration
> List<> list;                               // diamond on a field
> new <String>Box<>("x")                     // diamond combined with 
> constructor type arguments
> Outer<String, Integer>.Inner x;            // wrong arity
> x instanceof Outer<String>.Inner           // parameterized type is not 
> reifiable
> new Outer<String>.Inner[1]                 // generic array creation (JLS 
> 15.10.1)
> new Outer<?>.Nested[0]                     // static member from a 
> parameterized type (JLS 6.5.5)
> Outer<?>.Nested z;                         // same rule as a type name
> new Outer<?>.InnerG[0]                     // raw generic member of a 
> parameterized enclosing type
> class Bad implements Outer<String>.Iface<Integer> {} // nested interface is 
> implicitly static (JLS 9.5)
> new java.util.Map<?,?>.Entry[0]            // Map.Entry is a nested interface
> new Outer<?>().new Inner()                 // constructor type argument may 
> not be a wildcard
> {code}
> The {{Nested}} cases assume {{static class Nested}} inside {{Outer}}. The 
> {{InnerG}} array error is the raw-member form; the legal counterpart is {{new 
> Outer<?>.InnerG<?>[0]}} above.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to