Skip to content

Commit db635c5

Browse files
committed
Fix using the same previous data table column multiple times in the same cell (#2083)
1 parent 6c584d3 commit db635c5

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

spock-core/src/main/java/org/spockframework/compiler/WhereBlockRewriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ private void turnIntoSimpleParameterization(List<Expression> column) throws Inva
675675

676676
// otherwise generate the extractors and closure
677677
List<Statement> statements = new ArrayList<>();
678-
List<String> referencedPreviousVariables = previousVariableAccesses.stream().map(VariableExpression::getName).collect(toList());
678+
Set<String> referencedPreviousVariables = previousVariableAccesses.stream().map(VariableExpression::getName).collect(toSet());
679679
generatePreviousColumnExtractorStatements(referencedPreviousVariables, row, statements);
680680
ReturnStatement providerStatement = new ReturnStatement(providerExpression);
681681
providerStatement.setSourcePosition(providerExpression);
@@ -702,7 +702,7 @@ private void turnIntoSimpleParameterization(List<Expression> column) throws Inva
702702
rewriteSimpleParameterization(binExpr, varExpr, true);
703703
}
704704

705-
private void generatePreviousColumnExtractorStatements(List<String> referencedPreviousVariables, int row,
705+
private void generatePreviousColumnExtractorStatements(Set<String> referencedPreviousVariables, int row,
706706
List<Statement> statements) {
707707
for (String referencedPreviousVariable : referencedPreviousVariables) {
708708
statements.add(new ExpressionStatement(

spock-specs/src/test/groovy/org/spockframework/smoke/ast/DataTablesAstSpec.groovy

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package org.spockframework.smoke.ast
1616

1717
import org.spockframework.EmbeddedSpecification
1818
import org.spockframework.specs.extension.SpockSnapshotter
19+
import spock.lang.Issue
1920
import spock.lang.Snapshot
2021
import spock.util.Show
2122

@@ -83,4 +84,24 @@ class DataTablesAstSpec extends EmbeddedSpecification {
8384
then:
8485
snapshotter.assertThat(result.source).matchesSnapshot()
8586
}
87+
88+
@Issue('https://github.com/spockframework/spock/issues/2083')
89+
def 'using a variable in a cell multiple times compiles'() {
90+
given:
91+
snapshotter.featureBody()
92+
93+
when:
94+
def result = compiler.transpileFeatureBody '''
95+
expect:
96+
a + b == result
97+
98+
where:
99+
a | b | result
100+
1 | 2 | a + b
101+
3 | 4 | a + a // causes the compile error
102+
''', EnumSet.of(Show.METHODS)
103+
104+
then:
105+
snapshotter.assertThat(result.source).matchesSnapshot()
106+
}
86107
}

0 commit comments

Comments
 (0)