Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-10079

groovyc does not perform unboxing on Character type

    XMLWordPrintableJSON

Details

    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

          Activity

            People

              emilles Eric Milles
              theosot Thodoris Sotiropoulos
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: