You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Kenzie Togami (JIRA)" <ji...@apache.org> on 2018/10/06 08:55:00 UTC
[jira] [Created] (GROOVY-8828) Union types incorrectly resolved
Kenzie Togami created GROOVY-8828:
-------------------------------------
Summary: Union types incorrectly resolved
Key: GROOVY-8828
URL: https://issues.apache.org/jira/browse/GROOVY-8828
Project: Groovy
Issue Type: Bug
Components: Compiler
Affects Versions: 2.5.3, 2.4.13
Reporter: Kenzie Togami
UsingĀ {{@CompileStatic}} breaks {{Map#put}} if the operand is a UnionType due to this change (found by using {{git bisect}}): https://github.com/apache/groovy/commit/2e4413812fff5d2033e9eb163d734b539b079b6b
Error: {code}src/main/groovy/pkg/Main.groovy: 12: [Static type checking] - Cannot call java.util.LinkedHashMap <java.lang.String, pkg.Foo>#put(java.lang.String, pkg.Foo) with arguments [java.lang.String, <UnionTypepkg.Foo+pkg.Bar>]{code}
Sample code: https://gist.github.com/kenzierocks/8fd31525c0229caeb6c85622f5d230b5
Line 12 in Main.groovy will fail to compile.
There is a workaround for this, which is to explicitly cast the variable to the Map's type. Changing line 12 to {{map.put(name, (Foo) foo)}} will allow the code to compile. However, this is clearly not the expected behavior.
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)