Skip to content

containsKey missing method when in a with block #588

@mkobit

Description

@mkobit

I noticed this earlier when trying to make some assertions on a map.

Here is an example feature method with groovy-all:2.4.6 and spock-core:1.0-groovy-2.4 in gradle:

def "map containKey works as expected"() {
  given:
  def map = [myValue: 'hey', otherValue: 'helloagain']

  expect:
  with(map) {
    size() == 2
    containsKey('myValue')
    containsKey('otherValue')
  }
}

This fails with:

No signature of method: MySpec.containsKey() is applicable for argument types: (java.lang.String) values: [myValue]
groovy.lang.MissingMethodException: No signature of method: MySpec.containsKey() is applicable for argument types: (java.lang.String) values: [myValue]
    at MySpec.map containKey works as expected(MySpec.groovy:59)

If I change both of the containsKey methods instead to use the implicit it, like it.containsKey it works as expected.

Is this expected behavior? Am I missing something about how the AST transformations happen?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions