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

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

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

   ## ✅ All tests passed ✅
   
   🏷️ Commit: b27de77ee4adf8488ea9cf104fe80db7dea49f9a
   ▶️ Tests:  121665 executed
   ⚪️ Checks: 26/26 completed
   
   ---
   _Learn more about TestLens at 
[testlens.app/docs](https://testlens.app/docs/features/pr-comment/)._
   




> SC: a method reference to a functional interface with a primitive return type 
> fails at bootstrap when the return value needs a Groovy conversion (e.g. 
> String to boolean)
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12617
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12617
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 4.0.33, 5.0.8, 6.0.0
>            Reporter: Scott Murphy Heiberg
>            Priority: Major
>
> {code:groovy}
> import java.util.function.Predicate
> @groovy.transform.CompileStatic
> class C {
>     static String str(String s) { s }
>     static void main(args) {
>         Predicate<String> p = C::str
>         assert !p.test('') && p.test('x')
>     }
> }
> {code}
> Actual: the code compiles, but evaluating the method reference throws 
> {{java.lang.BootstrapMethodError}}, caused by 
> {{java.lang.invoke.LambdaConversionException: Type mismatch for lambda 
> expected return: class java.lang.String is not convertible to boolean}}. The 
> same happens for every primitive return that the type checker accepts but the 
> JVM cannot convert: boolean from any reference type or from int, 
> ToDoubleFunction from a BigDecimal method, and ToIntFunction from a long or 
> Long method.
> Expected: the value is converted as in dynamic Groovy, @TypeChecked code and 
> a method pointer ({{C.&str}}), which all give [false, true] here (Groovy 
> truth).
> Cause: the static compiler binds the method directly through 
> LambdaMetafactory, which converts a return value to a primitive type only by 
> unboxing and widening primitive conversion.
> Seen in 4.0.33, 5.0.8 and 6.0.0.
> PR: https://github.com/apache/groovy/pull/3143



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

Reply via email to