You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Eric Milles (Jira)" <ji...@apache.org> on 2021/05/16 18:49:00 UTC
[jira] [Assigned] (GROOVY-9983) Type argument inference does not
work in ternary operator
[ https://issues.apache.org/jira/browse/GROOVY-9983?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Eric Milles reassigned GROOVY-9983:
-----------------------------------
Assignee: Eric Milles
> Type argument inference does not work in ternary operator
> ---------------------------------------------------------
>
> Key: GROOVY-9983
> URL: https://issues.apache.org/jira/browse/GROOVY-9983
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation, Static Type Checker
> Reporter: Stefanos Chaliasos
> Assignee: Eric Milles
> Priority: Major
>
> I have the following Groovy program.
> {code:groovy}
> @groovy.transform.CompileStatic
> public class Test {
> public static void main(String[] args) {
> final A<B> x = (true ? new A<>(new B()): new A<>(new C()))
> bar(x) // compiles
> bar((true ? new A<>(new B()): new A<>(new C()))) // does not compile
> }
> public static void bar(A<B> x) {}
> }
> class A<T> {
> T f;
> public A(T f) {
> this.f = f;
> }
> }
> class B {}
> class C extends B{}
> {code}
> h2. Actual Behavior
> The program does not compile, and I get the following error.
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Test.groovy: 6: [Static type checking] - Cannot call Test#bar(A <B>) with arguments [A <? extends B>]
> @ line 6, column 7.
> bar((true ? new A<>(new B()): new A<>(new C())))
> ^
> 1 error
> {code}
> h2. Expected Behavior
> Compile successfully.
> h2. Comment
> This should be a regression bug because it compiles with the 4.0.0-alpha-2 compiler.
> h2. Affected Version
> This programs fails when compiled with the compiler from the master (commit: f0eea862549529ef4e93fafe337f86dd4ac98751).
--
This message was sent by Atlassian Jira
(v8.3.4#803005)