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

STC: different behavior w/ map subscript and property access when using elvis

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 2.0.2
    • 2.0.4
    • Static Type Checker
    • None

    Description

      There's a difference in behavior with static type checking between property and subscript access to map elements.

      @groovy.transform.TypeChecked
      class Test {
          static void test() {
              def m = [retries: 10]
              // passes
              int r1 = m['retries'] ?: 1
              // fails
              int r2 = m.retries ?: 1
          }   
      }
      
      Test.test()
      

      Fails with:

      [Static type checking] - Cannot assign value of type java.lang.Object to variable of type int
      

      Attachments

        Issue Links

          Activity

            People

              melix Cédric Champeau
              guillaume Guillaume Sauthier
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: