[ https://issues.apache.org/jira/browse/GROOVY-11414?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17859775#comment-17859775 ]
Eric Milles commented on GROOVY-11414: -------------------------------------- Looks like type checking has changed between 3 and 4 in this area. The expected return type is saved twice. First it's Long and then its V. If I stop the second writing, I get this error for the "1" expression: "Cannot return value of type int for lambda expecting java.lang.Long" > Compiler does not promote/check lambda results when required > ------------------------------------------------------------ > > Key: GROOVY-11414 > URL: https://issues.apache.org/jira/browse/GROOVY-11414 > Project: Groovy > Issue Type: Bug > Components: Compiler > Affects Versions: 4.0.21 > Reporter: Christopher Smith > Assignee: Eric Milles > Priority: Major > > Given this code, the Groovy compiler compiles it and happily inserts a > {{java.lang.Integer}} into a {{Map<String, Long}}. The Java compiler produces > a compile-time error for the same code, complaining that {{1}} is not a > {{Long}}. The result is the same for static and dynamic compilation: heap > pollution. > {code:groovy} > class Repro { > static Map<String, Long> map = new HashMap() > static void main(String... args) { > println map.computeIfAbsent('key', (__) -> 1) > println map.key.class > println map.compute('key', (__, Long existing) -> (existing ?: 0L) + > 2) > } > } > {code} > {code} > import java.util.HashMap; > import java.util.Map; > class ReproJava { > static Map<String, Long> map = new HashMap<>(); > static void main(String... args) { > map.computeIfAbsent("key", (__) -> 1); > map.compute("key", (__, existing) -> (existing != null ? existing : > 0L) + 2); > } > } > {code} -- This message was sent by Atlassian Jira (v8.20.10#820010)