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

Static type checking error when accessing class of a primitive type

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.1.7, 2.3.0, 2.4.0-beta-3
    • 2.4.1
    • Static Type Checker
    • None

    Description

      There is an inconsistency between the behaviour in runtime and in the static type checker when accessing the class of a Java primitive type. Suppose we have the following code:

      void runMethod (){
      int i = 10
      println(i.class)
      }
      
      runMethod()
      

      If I run this in the Groovy console everything runs fine, autoboxing is performed and 'class java.lang.Integer' is printed as the output. However, if I annotate the method with @groovy.transform.TypeChecked, there is an exception stating '[Static type checking] - No such property: class for class: int'. The same happens if I don't declare a variable and try to use a literal int instead.

      As far as I know, this happens with all the primitive types. In addition, trying to access their metaClass works well with or without the type checking enabled.

      I attach some of the examples I could come up with.

      Attachments

        1. TestCases.groovy
          0.4 kB
          Rodolfo Cruz

        Activity

          People

            Unassigned Unassigned
            rcruzjo Rodolfo Cruz
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: