Skip to content

Commit

Permalink
Fix using the same previous data table column multiple times in the s…
Browse files Browse the repository at this point in the history
…ame cell (#2083)
  • Loading branch information
Vampire committed Jan 15, 2025
1 parent 6c584d3 commit db635c5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ private void turnIntoSimpleParameterization(List<Expression> column) throws Inva

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

private void generatePreviousColumnExtractorStatements(List<String> referencedPreviousVariables, int row,
private void generatePreviousColumnExtractorStatements(Set<String> referencedPreviousVariables, int row,
List<Statement> statements) {
for (String referencedPreviousVariable : referencedPreviousVariables) {
statements.add(new ExpressionStatement(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package org.spockframework.smoke.ast

import org.spockframework.EmbeddedSpecification
import org.spockframework.specs.extension.SpockSnapshotter
import spock.lang.Issue
import spock.lang.Snapshot
import spock.util.Show

Expand Down Expand Up @@ -83,4 +84,24 @@ class DataTablesAstSpec extends EmbeddedSpecification {
then:
snapshotter.assertThat(result.source).matchesSnapshot()
}

@Issue('https://github.com/spockframework/spock/issues/2083')
def 'using a variable in a cell multiple times compiles'() {
given:
snapshotter.featureBody()

when:
def result = compiler.transpileFeatureBody '''
expect:
a + b == result
where:
a | b | result
1 | 2 | a + b
3 | 4 | a + a // causes the compile error
''', EnumSet.of(Show.METHODS)

then:
snapshotter.assertThat(result.source).matchesSnapshot()
}
}

0 comments on commit db635c5

Please sign in to comment.