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

Unable represent literal byte costant

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.5.9
    • 4.0.4
    • None

    Description

      Groovy does not allow the definition of literal byte constants. This makes impossible to express byte constant in some use cases.

      First example:

      public @interface Version {
       byte value();
      }
      
      class Foo {
       @Version(0x01) String bar
      }
      
      Error: Attribute 'value' should have type 'java.lang.Byte'; but found type 'int' in @Version
       

       

      Second example: 

      public @interface Version {
          byte value();
      }
      
      class Foo {
        @Version(1 as byte) String bar
      }
      
      Expected '(byte) 1' to be an inline constant of type byte in @Version
       at line: 6, column: 14Attribute 'value' should have type 'java.lang.Byte'; but found type 'java.lang.Object' in @Version
       at line: -1, column: -1 

       

      Third example: 

      public @interface Version {
          byte value();
      }
      
      class Foo {
        public static final byte ONE = 0b01
        @Version(ONE) String bar
      }
      
      Expected 'ONE' to be an inline constant of type byte not a field expression in @Version
       at line: 7, column: 12Attribute 'value' should have type 'java.lang.Byte'; but found type 'java.lang.Object' in @Version
       at line: -1, column: -1
       

       

       

       

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              pablo72 paolo di tommaso
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: