[
https://issues.apache.org/jira/browse/GROOVY-10081?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Eric Milles updated GROOVY-10081:
---------------------------------
Priority: Minor (was: Major)
> 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: Minor
>
> 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.20.10#820010)