You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Stefanos Chaliasos (Jira)" <ji...@apache.org> on 2021/03/15 09:37:00 UTC
[jira] [Created] (GROOVY-9983) Type argument inference does not
work in ternary operator
Stefanos Chaliasos created GROOVY-9983:
------------------------------------------
Summary: 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
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)