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

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

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.2
    • Fix Version/s: 2.0.4
    • Component/s: Static Type Checker
    • Labels:
      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

          Activity

            People

            • Assignee:
              melix C├ędric Champeau
              Reporter:
              Guillaume Guillaume Delcroix
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: