Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
None
-
None
Description
I have the following code
public class Main { public static char foo() { return (Character) 'd'; } }
Actual behaviour
groovyc rejects this code with
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: test.groovy: 4: [Static type checking] - Cannot return value of type java.lang.Character on method returning type char @ line 4, column 12. return (Character) 'd'; ^1 error
Expected behaviour
Compile successfully
Note that javac accepts this code. Beyond that, groovyc performs unboxing as expected when encountering other wrapper classes, e.g. Short. So, for example the following code is accepted by groovyc.
public class Main { public static short foo() { return (Short) 1; } }
Tested against master: https://github.com/apache/groovy/commit/1def25301b42132f0fce82f2f524aa09c53835d4
Attachments
Issue Links
- relates to
-
GROOVY-10359 STC misses type error when involving a variable with a char a declared type
- Closed