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/06/08 09:14:00 UTC
[jira] [Updated] (GROOVY-10114) Wrong type argument inference when
using the result of ternary operator directly.
[ https://issues.apache.org/jira/browse/GROOVY-10114?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Stefanos Chaliasos updated GROOVY-10114:
----------------------------------------
Component/s: Static Type Checker
Static compilation
> Wrong type argument inference when using the result of ternary operator directly.
> ---------------------------------------------------------------------------------
>
> Key: GROOVY-10114
> URL: https://issues.apache.org/jira/browse/GROOVY-10114
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation, Static Type Checker
> Affects Versions: 4.0.0-alpha-2, 3.0.8
> Reporter: Stefanos Chaliasos
> Priority: Major
>
> I have the following Groovy program.
> {code:groovy}
> @groovy.transform.TypeChecked
> class Test {
> public static void main(String[] args) {
> def x = ((false) ? new B<>(new A()) : new B<>(new A()))
> x.bar.foo()
> ((false) ? new B<A>(new A()) : new B<>(new A())).bar.foo()
> ((false) ? new B<>(new A()) : new B<>(new A())).bar.foo()
> }
> }
> final class A {
> public A() {
> }
> final Character foo() {
> (Character) 'g'
> }
> }
> class B<V> {
> public V bar
> public B(V bar) {
> this.bar = bar
> }
> }
> {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: 7: [Static type checking] - Cannot find matching method java.lang.Object#foo(). Please check if the declared type is correct and if the method exists.
> @ line 7, column 5.
> ((false) ? new B<>(new A()) : new B<>(new A())).bar.foo()
> ^
> 1 error
> {code}
> h2. Expected Behavior
> Compile successfully.
> h2. Comment
> This bug seems similar to GROOVY-9983, but it doesn't use subtyping. Moreover, in versions 3.0.8 and 4.0.0-alpha-2, the compiler produces the following error (in addition to the previous error message).
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Test.groovy: 5: [Static type checking] - Cannot find matching method java.lang.Object#foo(). Please check if the declared type is correct and if the method exists.
> @ line 5, column 5.
> x.bar.foo()
> ^
> {code}
> h2. Affected Version
> This programs have been tested with the compiler from the master (commit: c36c8bf3d24ce41e972e3f3e7a5763acf96f46b1), 4.0.0-alpha-2, and 3.0.8.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)