Björn Kautler created GROOVY-9494:
-------------------------------------
Summary: Closure in next line continues previous expression in 3.0
but didn't in 2.5
Key: GROOVY-9494
URL: https://issues.apache.org/jira/browse/GROOVY-9494
Project: Groovy
Issue Type: Bug
Affects Versions: 3.0.2
Reporter: Björn Kautler
The following snippet shows the problem.
Or rather it shows how it used to work as it is the Groovy 2.5 variant.
If you throw this in a Groovy 2.5 console and open the AST Browser at end of
phase {{Semantic Analysis}}, everything is fine:
{code:java}
@Grab('org.spockframework:spock-core:2.0-M2-groovy-2.5')
import spock.lang.*
class Foo extends Specification {
def foo() {
expect:
a() == 1
b == 2
where:
a | b
{ it -> 1 } | 2
}
}{code}
If you now open a Groovy 3.0 console, throw in the same snippet (with the
{{groovy-3.0}} dependency of Spock of course) and again open the AST Browser,
you get a complaint that the header of a data table must only contain variable
names ({{a}} and {{b}}).
Of course this is a message from Spocks AST transformations, but the root cause
is, that there is a regression (at least I hope it is a regression, not
intention :)) in Groovy as the logic when a linebreak ends a statement and when
not. This makes code (in this case tests) working perfectly fine in Groovy 2.5
suddenly behaving differently or not compiling with Groovy 3.0.
The problem might not always result in a compilation error.
It does so in this example but could also "just" lead to a change in behaviour.
The Groovy 3.0 parser results in this:
{code:java}
import spock.lang.*
public class Foo extends Specification {
public java.lang.Object foo() {
this.a() == 1
b == 2
a | this.b({ java.lang.Object it ->
1
}) | 2
}
} {code}
while the Groovy 2.5 parser resulted in this:
{code:java}
import spock.lang.*
public class Foo extends Specification {
public java.lang.Object foo() {
this.a() == 1
b == 2
a | b
{ java.lang.Object it ->
1
} | 2
}
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)