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

Weird behavior of !in operator

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.9
    • 4.0.0-beta-2, 3.0.10
    • None
    • None

    Description

      After upgrading to 3.0.9, I've noticed some unexpected behavior around the "!in" operator. Consider the following example:

      import groovy.transform.CompileStatic
      
      @CompileStatic
      class MyPogo {
        String firstName
        String lastName
      }
      
      @CompileStatic
      class Test {
        void testMe() {
          MyPogo myPogo = new MyPogo(firstName: "My First Name", lastName: "My Last Name")
          Map<String, ?> filteredProperties = myPogo.properties.findAll { 
            Boolean result = it.key as String !in ["class"]
            result
          }
          println filteredProperties
          assert filteredProperties.size() == 2
          
          filteredProperties = myPogo.properties.findAll { 
            (it.key as String !in ["class"]) as Boolean
          }    
          println filteredProperties
          assert filteredProperties.size() == 2
          
          filteredProperties = myPogo.properties.findAll { 
            it.key as String !in ["class"]
          }    
          println filteredProperties
          assert filteredProperties.size() == 2
        }
      }
      
      new Test().testMe()
      

      When running it in GroocyConsole, the third assertion will fail without apparent reason.
      It looks like for "!in" to work correctly, some additional operation is required.

      The same code works for the 3.0.8 and 3.0.7 versions.
      Tnx

      Attachments

        Issue Links

          Activity

            People

              emilles Eric Milles
              dmurat Damir Murat
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: