spockframework / spockframework/spock
Multi-assignment statement in "setup" block does not compile
Open
Nobody has claimed this yet.
Module-Core
Type-Defect
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 483
- PR merge metrics
- No merged PRs in 30d
Description
Originally reported on Google Code with ID 373
I have a "setup" block in my test with the following code:
def (parentGroupId, childGroupId1, childGroupId2) = createGroupWithAssociations()
The method being invoked returns a List of three items. When I try to run the test
I get the following compilation error:
java.lang.ClassCastException: org.codehaus.groovy.ast.expr.ArgumentListExpression
cannot be cast to org.codehaus.groovy.ast.expr.VariableExpression
at org.codehaus.groovy.ast.expr.DeclarationExpression.getVariableExpression(DeclarationExpression.java:100)
at org.spockframework.compiler.SpecRewriter.moveVariableDeclarations(SpecRewriter.java:538)
...
See attachment for full stacktrace.
When I rewrite the code so that it doesn't use Groovy's multi-assignment, the test
compiles and passes fine:
def groupIds = createGroupWithAssociations()
def parentGroupId = groupIds[0]
def childGroupId1 = groupIds[1]
def childGroupId2 = groupIds[2]
Using Grails 2.3.8 and thus:
=> spock-core:0.7-groovy-2.0
=> groovy-all:2.1.9
Please provide any additional information below. You can also assign
labels.
Reported by vpaziran on 2014-08-14 21:55:32
- _Attachment: [spock-compile-error-groovy-multi-assignment-not-working.txt](https://storage.googleapis.com/google-code-attachments/spock/issue-373/comment-0/spock-compile-error-groovy-multi-assignment-not-working.txt)_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the setup-block example with spock-core 0.7-groovy-2.0 and groovy-all 2.1.9, then follow the reported stack trace through SpecRewriter.moveVariableDeclarations and DeclarationExpression.getVariableExpression. Done means the multi-assignment compiles and the test passes without the ClassCastException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- compilers, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100