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:17:00 UTC

[jira] [Updated] (GROOVY-10081) Conversion from int to byte does not work in case of ternary operator

     [ https://issues.apache.org/jira/browse/GROOVY-10081?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefanos Chaliasos updated GROOVY-10081:
----------------------------------------
    Component/s: Static Type Checker
                 Static compilation

> Conversion from int to byte does not work in case of ternary operator
> ---------------------------------------------------------------------
>
>                 Key: GROOVY-10081
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10081
>             Project: Groovy
>          Issue Type: Bug
>          Components: Static compilation, Static Type Checker
>            Reporter: Stefanos Chaliasos
>            Priority: Major
>
> I have the following Groovy program.
> {code:groovy}
> @groovy.transform.CompileStatic
> public class Main {
>   static byte x = 1;
>   public static byte foo() {
>     1
>   }
>   public static void main(String[] args) {
>     x = (true) ? 0 : foo() // this does not work
>     // the following works
>     if (true) {
>       x = 0
>     } else {
>       x = foo()
>     }
>     byte y = (true) ? 0 : foo() // this doesn't work as well
>   }
> }
> {code}
> h2. Actual Behavior
> The program does not compile, and I get the following error.
> {code:java}
> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
> Main.groovy: 11: [Static type checking] - Possible loss of precision from int to byte
>  @ line 11, column 9.
>        x = (true) ? 0 : foo() 
>            ^
> Main.groovy: 20: [Static type checking] - Possible loss of precision from int to byte
>  @ line 20, column 14.
>        byte y = (true) ? 0 : foo() 
>                 ^
> 2 errors
> {code}
> h2. Expected Behavior
> Compile successfully.
> h2. Affected Version
> This programs fails when compiled with the compiler from the master (commit: a8023b1b0d1d79800677ce2b4665ee3fb14688f4), 4.0.0-alpha-2, and 3.0.8.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)