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

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

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

   ## 🚨 TestLens detected 1 failed test 🚨
   
   ### Test Summary
   > [!TIP]
   > Inspect all details with the [TestLens 
CLI](https://testlens.app/docs/features/cli): `testlens pr 3265`
   
   #### [Build and test / lts \(17, 
ubuntu-latest\)](https://github.com/apache/groovy/actions/runs/45059221919/job/137321159014?pr=3265)
 > :test
   
   | Test | Runs | Flakiness |
   |---|---|--:|
   | RegressionTest > testGroovy12727\(\) | ❌ | 0% 🟢 |
   
   🏷️ Commit: 4d4e2423dc7a9b95cb040bac972ba4487223c7b7
   ▶️ Tests:  31833 executed
   🟡 Checks: 7/24 completed
   
   ### Test Failures
   
   <details><summary><strong>RegressionTest > testGroovy12727()</strong> (:test 
in <a 
href="https://github.com/apache/groovy/actions/runs/45059221919/job/137321159014?pr=3265";>Build
 and test / lts (17, ubuntu-latest)</a>)</summary>
   
   ```
   java.lang.AssertionError: Method is marked with @NotYetImplemented but 
passes unexpectedly
        at bugs.RegressionTest.testGroovy12727(RegressionTest.groovy:5248)
   ```
   
   </details>
   
   ### Rerun Controls
   > [!NOTE]
   > Checks are currently running using the configuration below.
   
   Select tests to mute in this pull request:
   
   🔲 RegressionTest > testGroovy12727\(\) <!

> STC: a generic method's type parameter isn't inferred from the return-type 
> target when the argument is a lambda
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12727
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12727
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Paul King
>            Assignee: Paul King
>            Priority: Major
>
> Under {{@TypeChecked}} (and {{@CompileStatic}}), when a generic method's only 
> argument is an implicitly typed lambda, the type parameter is not inferred 
> from the expected return type. The lambda's parameter is typed with a 
> wildcard ({{Ctx<? extends Object>}}), and a call inside the lambda that needs 
> the concrete type is rejected. javac infers {{T = String}} from the 
> return-type target and compiles the equivalent Java.
> This is the standard Apache Pekko (and Akka) typed-actor factory, 
> {{Behaviors.setup(context -> new MyActor(context))}}, so statically compiled 
> Pekko code needs a type witness or an explicitly typed lambda parameter.
> h3. Repro (no dependencies)
> {code:groovy}
> import java.util.function.Function
> import groovy.transform.TypeChecked
> class Ctx<T> {}
> class Beh<T> {}
> class Behaviors {
>     static <T> Beh<T> setup(Function<Ctx<T>, Beh<T>> factory) { 
> factory.apply(new Ctx<T>()) }
> }
> class Bot extends Beh<String> {
>     Bot(Ctx<String> c, int max) {}
> }
> @TypeChecked
> class M {
>     static Beh<String> lambda(int max) { Behaviors.setup(c -> new Bot(c, 
> max)) }
> }
> {code}
> h3. Actual
> {noformat}
> [Static type checking] - Cannot call Bot#<init>(Ctx<java.lang.String>, int) 
> with arguments [Ctx<? extends java.lang.Object>, int]
> {noformat}
> h3. Expected
> Compiles, as the Java equivalent does with javac ({{T}} inferred as 
> {{String}} from the {{Beh<String>}} return type).
> h3. Workarounds (both compile on 6.0.0)
> {code:groovy}
> Behaviors.<String>setup(c -> new Bot(c, max))                 // explicit 
> type witness
> Behaviors.setup((Ctx<String> c) -> new Bot(c, max))          // explicitly 
> typed lambda parameter
> {code}
> h3. Notes
> * The closure form, Behaviors.setup \{ c -> new Bot(c, max) }, fails with the 
> same message.
> * An assignment target fails the same way as a return target: {{Beh<String> b 
> = Behaviors.setup(c -> new Bot(c, max))}}.
> * Possibly related, not duplicates:
> ** GROOVY-11446: target-type handling for a generic method with wildcards, in 
> the opposite direction (accepted when it should fail).
> ** GROOVY-11077: lambda parameter types from a wildcard SAM; no generic 
> method or inference involved.
> ** GROOVY-12714 / PR #3246: javac-compatibility changes to wildcard 
> containment in the same visitor; they don't appear to supply this inference 
> (not verified against the branch).



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

Reply via email to