File tree Expand file tree Collapse file tree 2 files changed +23
-2
lines changed
spock-core/src/main/java/org/spockframework/compiler
spock-specs/src/test/groovy/org/spockframework/smoke/ast Expand file tree Collapse file tree 2 files changed +23
-2
lines changed Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ package org.spockframework.smoke.ast
1616
1717import org.spockframework.EmbeddedSpecification
1818import org.spockframework.specs.extension.SpockSnapshotter
19+ import spock.lang.Issue
1920import spock.lang.Snapshot
2021import 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}
You can’t perform that action at this time.
0 commit comments