New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AST transformation messes up setter/getter in dot-property notation #1158
Comments
Thanks @kriegaex, appreciate you taking the time to confirm the bug in different versions as well as opening this bug. |
Update: Actually I just noticed that if the application classes are implemented in Java, it works as expected with the property notation for setters/getters. The problem seems to be related to |
Thanks for your report with detailed use cases! It is a known reason I spotted working on Groovy 3 compatibility - #1076. There is a workaround (a hack) to handle common cases (for Groovy 3 - which explains that more tests pass), but as it is not a problem which hits the majority of people, I would wait until https://issues.apache.org/jira/browse/GROOVY-9369 is fixed on the Groovy side. |
From the discussion in the other ticket and the ML it sounds as if this is purely a Groovy 3 problem, which it is not. On the contrary, more tests fail in Groovy 2 than in Groovy 3, but - as I said - only in Spock, not in pure Groovy. So to me it sounds as if even a future Groovy 3 fix will not help us on Spock 1.x with Groovy 2 or Spock 2.x with Groovy 2. I am not an AST expert, but my gut feeling tells me that this ought to (and could) be fixed in Spock. Maybe it can be analysed and differentiated in an AST phase earlier than the one used at the moment, i.e. before the AST has been transformed to a point where you can no longer differentiate what the user wrote in the source code and which intention she has. |
Please take a look at the following code and again at my description in the reported issue in Groovy. As the Groovy developers confirmed (on Slack) it could be a problem in 3.x and proposed to report the bug to take a look at it later on, I would prefer to avoid "additional hacks" to handle edge cases. However, I definitely could miss something, so if you have a good idea how to easily fix it (in a sensible way) on the Spock side please propose required changes. |
Actually I am just a Spock user and not a Groovy pro, so I am afraid I cannot say anything intelligent about your code. But again the question: How can this be a Groovy 3 problem if it also happens in Groovy 2? My sample code and the provided logs prove it. |
Trying to fix the issues with Groovy 3, I also spotted that some corner cases with mocking were already broken in the previous Spock versions with Groovy 2. Unfortunately, AFAIR I didn't have a good idea how to fix it without more "fragile hacks" (and it seems to be not very often used). Maybe it will be easier to cover in some sensible way at least for Groovy 3. |
What about my idea to look into it in an earlier AST phase and transform it into something unambiguous for the later phase Spock usually operates on? AFAIR Spock only works in one phase. |
I'd like to add that this issue practically breaks all our stubs of classes with abstract superclasses. With a String property "bar" on stub "foo", the following happens:
|
I just built master and the above specification (Some other spec for parallel test execution failed on my Windows machine, but that is off-topic here.) |
I found this on StackOverflow. Here is my slightly modifed version of the sample code:
Running this test in Spock 1.3-groovy-2.5 yields 4 failed tests:
Running the exact same test on Spock 2.0-M2-groovy-3.0 yields only 2 failed tests:
Running the
main
method on both platforms shows that it is not a Groovy problem but probably related to a Spock AST transformation glitch:The text was updated successfully, but these errors were encountered: