Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
None
-
None
-
None
Description
I have the following Groovy program.
@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 } }
Actual Behavior
The program does not compile, and I get the following error.
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
Expected Behavior
Compile successfully.
Affected Version
This programs fails when compiled with the compiler from the master (commit: a8023b1b0d1d79800677ce2b4665ee3fb14688f4), 4.0.0-alpha-2, and 3.0.8.