Issues with Groovy 5 and with
#2275
Answered
by
jochenberger
jochenberger
asked this question in
Q&A
-
|
Hi, I found some odd behavior when migrating one of my projects to Groovy 5. I'm not sure whether it's to be expected. It seems to have something to do with how properties are resolved inside closures. @Grab(group='org.spockframework', module='spock-core', version='2.4-M7-groovy-5.0')
import spock.lang.*
class TestSpec extends Specification {
static Locale DE = Locale.GERMAN
def "foo"(){
given:
Map m = ['de': 'foo']
expect:
m.(DE) == 'foo'
with(m){
it.(Locale.GERMAN) == 'foo' // works
it.(this.DE) == 'foo' // works
it.(DE) == 'foo' // fails
}
}
}The output is With the Groovy 4 module, the test passes. Can someone please help me understand what's going on here? |
Beta Was this translation helpful? Give feedback.
Answered by
jochenberger
Dec 2, 2025
Replies: 1 comment 2 replies
-
|
Oh, this is interesting: @Grab(group='org.spockframework', module='spock-core', version='2.4-M7-groovy-5.0')
import spock.lang.*
class TestSpec extends Specification {
static Locale DE = Locale.GERMAN
def "foo"(){
expect:
DE == Locale.GERMAN
with(''){
DE == Locale.GERMAN // works
}
with([DE:Locale.GERMAN]){
DE == Locale.GERMAN // works
}
with([:]){
DE == Locale.GERMAN // fails with Groovy 5 but works with 4.
}
}
}So, if the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, it seems to have changed in Groovy 5.
That prints 'bar' in Groovy 4 and 'null' in Groovy 5.