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

bytecode for in, !in, !() and ?:

    XMLWordPrintableJSON

Details

    Description

      Consider the following:

      List getList() { ['xx'] }
      @groovy.transform.CompileStatic
      void test(object) {
        def others = [], strings = []
        if (object in list) { // 4 of 8 branches missed
          strings << object
        }
        if (!(object in list)) { // 4 of 10 branched missed
          others << object
        }
        println others
        println strings
      }
      test(null)
      test('xx')
      test([''])
      

      When unit testing, I noticed 4 of 10 branches missed for "if (!(item in list)) ...". When compiled and executed dynamically, it shows 2 of 2 branches covered (safe call to "list.isCase(item)").

      Static compilation transforms "item in list" into "list == null ? item == null : list.isCase(item)". This is certainly where all the branches are coming from.

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              emilles Eric Milles
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: