You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "daniellansun (via GitHub)" <gi...@apache.org> on 2025/04/02 16:57:40 UTC
[PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
daniellansun opened a new pull request, #2172:
URL: https://github.com/apache/groovy/pull/2172
https://issues.apache.org/jira/browse/GROOVY-4721
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "daniellansun (via GitHub)" <gi...@apache.org>.
daniellansun commented on code in PR #2172:
URL: https://github.com/apache/groovy/pull/2172#discussion_r2029274400
##########
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy:
##########
@@ -392,17 +394,34 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
}
}
+ // groovy:000> int x = 3
+ // ===> 3
+ // groovy:000> x
+ // Unknown property: x
+ // groovy:000> x = 3
+ // ===> 3
+ // groovy:000> x
+ // ===> 3
+ // groovy:000>
void testBoundVar() {
Groovysh groovysh = createGroovysh()
- groovysh.execute('int x = 3')
+ groovysh.execute('x = 3')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
groovysh.execute('x')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
}
+ // collecting variables relies on GROOVY-4721, e.g. accessing variable declared in try block is in scope in finally block
+ // but after GROOVY-4721 is fixed, this test will fail, but it is aligned with the behavior of the groovySh:
+ // groovy:000> int x, y, z
+ // ===> 0
+ // groovy:000> y
+ // Unknown property: y
+ // groovy:000>
+ @NotYetImplemented
Review Comment:
https://github.com/apache/groovy/blob/87390561659f50e5a117bebb697731e8666f97b3/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy#L294
Groovysh will try to collect variables in the `finally` block, but variables declared in `try` block can not be accessed in `finally` block after GROOVY-4721 is fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "daniellansun (via GitHub)" <gi...@apache.org>.
daniellansun commented on code in PR #2172:
URL: https://github.com/apache/groovy/pull/2172#discussion_r2035885431
##########
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy:
##########
@@ -392,17 +394,34 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
}
}
+ // groovy:000> int x = 3
+ // ===> 3
+ // groovy:000> x
+ // Unknown property: x
+ // groovy:000> x = 3
+ // ===> 3
+ // groovy:000> x
+ // ===> 3
+ // groovy:000>
void testBoundVar() {
Groovysh groovysh = createGroovysh()
- groovysh.execute('int x = 3')
+ groovysh.execute('x = 3')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
groovysh.execute('x')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
}
+ // collecting variables relies on GROOVY-4721, e.g. accessing variable declared in try block is in scope in finally block
+ // but after GROOVY-4721 is fixed, this test will fail, but it is aligned with the behavior of the groovySh:
+ // groovy:000> int x, y, z
+ // ===> 0
+ // groovy:000> y
+ // Unknown property: y
+ // groovy:000>
+ @NotYetImplemented
Review Comment:
@paulk-asert I've polished the PR as you suggested:
https://github.com/apache/groovy/pull/2172/commits/fef0b8cf6a6e7c4a472afa207808d091fdac354d
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "daniellansun (via GitHub)" <gi...@apache.org>.
daniellansun commented on code in PR #2172:
URL: https://github.com/apache/groovy/pull/2172#discussion_r2029274400
##########
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy:
##########
@@ -392,17 +394,34 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
}
}
+ // groovy:000> int x = 3
+ // ===> 3
+ // groovy:000> x
+ // Unknown property: x
+ // groovy:000> x = 3
+ // ===> 3
+ // groovy:000> x
+ // ===> 3
+ // groovy:000>
void testBoundVar() {
Groovysh groovysh = createGroovysh()
- groovysh.execute('int x = 3')
+ groovysh.execute('x = 3')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
groovysh.execute('x')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
}
+ // collecting variables relies on GROOVY-4721, e.g. accessing variable declared in try block is in scope in finally block
+ // but after GROOVY-4721 is fixed, this test will fail, but it is aligned with the behavior of the groovySh:
+ // groovy:000> int x, y, z
+ // ===> 0
+ // groovy:000> y
+ // Unknown property: y
+ // groovy:000>
+ @NotYetImplemented
Review Comment:
https://github.com/apache/groovy/blob/87390561659f50e5a117bebb697731e8666f97b3/subprojects/groovy-groovysh/src/main/groovy/org/apache/groovy/groovysh/Groovysh.groovy#L294
Groovysh will try to collect variables in the `finally` block, but variables declared in `try` block can not be accessed in `finally` after GROOVY-4721 is fixed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on code in PR #2172:
URL: https://github.com/apache/groovy/pull/2172#discussion_r2028777348
##########
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy:
##########
@@ -392,17 +394,34 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
}
}
+ // groovy:000> int x = 3
+ // ===> 3
+ // groovy:000> x
+ // Unknown property: x
+ // groovy:000> x = 3
+ // ===> 3
+ // groovy:000> x
+ // ===> 3
+ // groovy:000>
void testBoundVar() {
Groovysh groovysh = createGroovysh()
- groovysh.execute('int x = 3')
+ groovysh.execute('x = 3')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
groovysh.execute('x')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
}
+ // collecting variables relies on GROOVY-4721, e.g. accessing variable declared in try block is in scope in finally block
+ // but after GROOVY-4721 is fixed, this test will fail, but it is aligned with the behavior of the groovySh:
+ // groovy:000> int x, y, z
+ // ===> 0
+ // groovy:000> y
+ // Unknown property: y
+ // groovy:000>
+ @NotYetImplemented
Review Comment:
I would like to fix the original issue, but it would be good to not break interpreterMode. I'll try to find time to investigate a little more.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "daniellansun (via GitHub)" <gi...@apache.org>.
daniellansun commented on code in PR #2172:
URL: https://github.com/apache/groovy/pull/2172#discussion_r2034205488
##########
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy:
##########
@@ -392,17 +394,34 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
}
}
+ // groovy:000> int x = 3
+ // ===> 3
+ // groovy:000> x
+ // Unknown property: x
+ // groovy:000> x = 3
+ // ===> 3
+ // groovy:000> x
+ // ===> 3
+ // groovy:000>
void testBoundVar() {
Groovysh groovysh = createGroovysh()
- groovysh.execute('int x = 3')
+ groovysh.execute('x = 3')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
groovysh.execute('x')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
}
+ // collecting variables relies on GROOVY-4721, e.g. accessing variable declared in try block is in scope in finally block
+ // but after GROOVY-4721 is fixed, this test will fail, but it is aligned with the behavior of the groovySh:
+ // groovy:000> int x, y, z
+ // ===> 0
+ // groovy:000> y
+ // Unknown property: y
+ // groovy:000>
+ @NotYetImplemented
Review Comment:
We can wrap the `current` with `try-finally` to guarantee the variables will be collected eventually.
I will polish the PR tonight.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #2172:
URL: https://github.com/apache/groovy/pull/2172#issuecomment-2773198131
## [Codecov](https://app.codecov.io/gh/apache/groovy/pull/2172?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
Attention: Patch coverage is `87.50000%` with `1 line` in your changes missing coverage. Please review.
> Project coverage is 68.8448%. Comparing base [(`6ce967f`)](https://app.codecov.io/gh/apache/groovy/commit/6ce967f8019f175e589e71873f025b0a16bb0a13?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to head [(`9413b2d`)](https://app.codecov.io/gh/apache/groovy/commit/9413b2dd224b1928270e69e6b5e6f57d42230b67?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
| [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2172?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [.../codehaus/groovy/classgen/asm/StatementWriter.java](https://app.codecov.io/gh/apache/groovy/pull/2172?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2FStatementWriter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9TdGF0ZW1lbnRXcml0ZXIuamF2YQ==) | 87.5000% | [0 Missing and 1 partial :warning: ](https://app.codecov.io/gh/apache/groovy/pull/2172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
<details><summary>Additional details and impacted files</summary>
[](https://app.codecov.io/gh/apache/groovy/pull/2172?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
```diff
@@ Coverage Diff @@
## master #2172 +/- ##
==================================================
+ Coverage 68.8443% 68.8448% +0.0005%
- Complexity 29533 29535 +2
==================================================
Files 1421 1421
Lines 113424 113429 +5
Branches 19644 19644
==================================================
+ Hits 78086 78090 +4
- Misses 28754 28755 +1
Partials 6584 6584
```
| [Files with missing lines](https://app.codecov.io/gh/apache/groovy/pull/2172?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [.../codehaus/groovy/classgen/asm/StatementWriter.java](https://app.codecov.io/gh/apache/groovy/pull/2172?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fclassgen%2Fasm%2FStatementWriter.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2NsYXNzZ2VuL2FzbS9TdGF0ZW1lbnRXcml0ZXIuamF2YQ==) | `96.8927% <87.5000%> (-0.2420%)` | :arrow_down: |
... and [5 files with indirect coverage changes](https://app.codecov.io/gh/apache/groovy/pull/2172/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
</details>
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "daniellansun (via GitHub)" <gi...@apache.org>.
daniellansun merged PR #2172:
URL: https://github.com/apache/groovy/pull/2172
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "daniellansun (via GitHub)" <gi...@apache.org>.
daniellansun commented on code in PR #2172:
URL: https://github.com/apache/groovy/pull/2172#discussion_r2034205488
##########
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy:
##########
@@ -392,17 +394,34 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
}
}
+ // groovy:000> int x = 3
+ // ===> 3
+ // groovy:000> x
+ // Unknown property: x
+ // groovy:000> x = 3
+ // ===> 3
+ // groovy:000> x
+ // ===> 3
+ // groovy:000>
void testBoundVar() {
Groovysh groovysh = createGroovysh()
- groovysh.execute('int x = 3')
+ groovysh.execute('x = 3')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
groovysh.execute('x')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
}
+ // collecting variables relies on GROOVY-4721, e.g. accessing variable declared in try block is in scope in finally block
+ // but after GROOVY-4721 is fixed, this test will fail, but it is aligned with the behavior of the groovySh:
+ // groovy:000> int x, y, z
+ // ===> 0
+ // groovy:000> y
+ // Unknown property: y
+ // groovy:000>
+ @NotYetImplemented
Review Comment:
We can wrap the `current` with `try-finally` to guarantee the variables will be collected eventually.
I will polish the PR tonight.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on code in PR #2172:
URL: https://github.com/apache/groovy/pull/2172#discussion_r2030997973
##########
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy:
##########
@@ -392,17 +394,34 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
}
}
+ // groovy:000> int x = 3
+ // ===> 3
+ // groovy:000> x
+ // Unknown property: x
+ // groovy:000> x = 3
+ // ===> 3
+ // groovy:000> x
+ // ===> 3
+ // groovy:000>
void testBoundVar() {
Groovysh groovysh = createGroovysh()
- groovysh.execute('int x = 3')
+ groovysh.execute('x = 3')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
groovysh.execute('x')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
}
+ // collecting variables relies on GROOVY-4721, e.g. accessing variable declared in try block is in scope in finally block
+ // but after GROOVY-4721 is fixed, this test will fail, but it is aligned with the behavior of the groovySh:
+ // groovy:000> int x, y, z
+ // ===> 0
+ // groovy:000> y
+ // Unknown property: y
+ // groovy:000>
+ @NotYetImplemented
Review Comment:
I added the change to StatementWriter and changed groovysh to just have the "variableBlocks" execute directly after "current" (i.e. just removed the try...finally) then interpreterMode still seemed to work. The current test suite and the new tests all passed. There could be variations that we don't have coverage for in our test suite that may become broken with that change.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "paulk-asert (via GitHub)" <gi...@apache.org>.
paulk-asert commented on code in PR #2172:
URL: https://github.com/apache/groovy/pull/2172#discussion_r2028683776
##########
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy:
##########
@@ -392,17 +394,34 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
}
}
+ // groovy:000> int x = 3
+ // ===> 3
+ // groovy:000> x
+ // Unknown property: x
+ // groovy:000> x = 3
+ // ===> 3
+ // groovy:000> x
+ // ===> 3
+ // groovy:000>
void testBoundVar() {
Groovysh groovysh = createGroovysh()
- groovysh.execute('int x = 3')
+ groovysh.execute('x = 3')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
groovysh.execute('x')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
}
+ // collecting variables relies on GROOVY-4721, e.g. accessing variable declared in try block is in scope in finally block
+ // but after GROOVY-4721 is fixed, this test will fail, but it is aligned with the behavior of the groovySh:
+ // groovy:000> int x, y, z
+ // ===> 0
+ // groovy:000> y
+ // Unknown property: y
+ // groovy:000>
+ @NotYetImplemented
Review Comment:
This isn't the existing behavior of groovysh with interpreterMode set.
> groovy:000> :set interpreterMode
> groovy:000> int x = 3
> ===> 3
> groovy:000> x
> ===> 3
> groovy:000> int a, b, c
> ===> 0
> groovy:000> b
> ===> 0
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "daniellansun (via GitHub)" <gi...@apache.org>.
daniellansun commented on code in PR #2172:
URL: https://github.com/apache/groovy/pull/2172#discussion_r2034205488
##########
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy:
##########
@@ -392,17 +394,34 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
}
}
+ // groovy:000> int x = 3
+ // ===> 3
+ // groovy:000> x
+ // Unknown property: x
+ // groovy:000> x = 3
+ // ===> 3
+ // groovy:000> x
+ // ===> 3
+ // groovy:000>
void testBoundVar() {
Groovysh groovysh = createGroovysh()
- groovysh.execute('int x = 3')
+ groovysh.execute('x = 3')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
groovysh.execute('x')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
}
+ // collecting variables relies on GROOVY-4721, e.g. accessing variable declared in try block is in scope in finally block
+ // but after GROOVY-4721 is fixed, this test will fail, but it is aligned with the behavior of the groovySh:
+ // groovy:000> int x, y, z
+ // ===> 0
+ // groovy:000> y
+ // Unknown property: y
+ // groovy:000>
+ @NotYetImplemented
Review Comment:
We can wrap the `current` with `try-finally` to guarantee the variables will be collected eventually.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] GROOVY-4721: variable declared in try block is in scope in finally block [groovy]
Posted by "daniellansun (via GitHub)" <gi...@apache.org>.
daniellansun commented on code in PR #2172:
URL: https://github.com/apache/groovy/pull/2172#discussion_r2031095137
##########
subprojects/groovy-groovysh/src/test/groovy/org/apache/groovy/groovysh/GroovyshTest.groovy:
##########
@@ -392,17 +394,34 @@ class GroovyshInterpreterModeTest extends GroovyshTest {
}
}
+ // groovy:000> int x = 3
+ // ===> 3
+ // groovy:000> x
+ // Unknown property: x
+ // groovy:000> x = 3
+ // ===> 3
+ // groovy:000> x
+ // ===> 3
+ // groovy:000>
void testBoundVar() {
Groovysh groovysh = createGroovysh()
- groovysh.execute('int x = 3')
+ groovysh.execute('x = 3')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
groovysh.execute('x')
assert mockOut.toString().length() > 0
assert ' 3\n' == mockOut.toString().normalize()[-3..-1]
}
+ // collecting variables relies on GROOVY-4721, e.g. accessing variable declared in try block is in scope in finally block
+ // but after GROOVY-4721 is fixed, this test will fail, but it is aligned with the behavior of the groovySh:
+ // groovy:000> int x, y, z
+ // ===> 0
+ // groovy:000> y
+ // Unknown property: y
+ // groovy:000>
+ @NotYetImplemented
Review Comment:
if the code of `current` throws an exception, the variables will still fail to collect.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@groovy.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org