[rubysrc2cpg] Change for-loop lowering#6023
Open
TNSelahle wants to merge 8 commits into
Open
Conversation
ml86
requested changes
Jun 17, 2026
Comment on lines
+484
to
+485
| base.argumentIndex shouldBe 0 | ||
| base.name shouldBe "x" |
Contributor
There was a problem hiding this comment.
That is not correct. There should be some sort of range object representing (1..x).
Member
Author
There was a problem hiding this comment.
This is correct. The test case had 2 separate for loops. I've split them up for better readability now.
Comment on lines
+491
to
+495
| inside(cpg.method("foo1").astChildren.collectAll[Method].isLambda.l) { case closureMethod :: Nil => | ||
| inside(closureMethod.parameter.indexGt(0).l) { case iParam :: Nil => | ||
| iParam.name shouldBe "i" | ||
| } | ||
|
|
||
| closureMethod.call.nameExact("puts").size shouldBe 1 |
Contributor
There was a problem hiding this comment.
There needs to be a captured variable for x. Test for it.
Comment on lines
+510
to
+514
| inside(cpg.method("foo2").astChildren.collectAll[Method].isLambda.l) { case closureMethod :: Nil => | ||
| inside(closureMethod.parameter.indexGt(0).l) { case iParam :: Nil => | ||
| iParam.name shouldBe "i" | ||
| } | ||
| closureMethod.call.nameExact("puts").size shouldBe 1 |
Contributor
There was a problem hiding this comment.
Again missing the test for the captured variable.
Comment on lines
+737
to
+742
| inside(cpg.method.isModule.astChildren.collectAll[Method].isLambda.l) { case closureMethod :: Nil => | ||
| inside(closureMethod.parameter.indexGt(0).l) { case numParam :: Nil => | ||
| numParam.name shouldBe "num" | ||
| } | ||
| val List(putsCall) = closureMethod.call.nameExact("puts").l | ||
| putsCall.code shouldBe "puts num" |
Contributor
There was a problem hiding this comment.
Again captured variable test.
ml86
approved these changes
Jun 19, 2026
Comment on lines
471
to
476
| |def foo2 | ||
| | x = 3 | ||
| | for i in 1..x do | ||
| | puts x + i | ||
| | end | ||
| |end |
Contributor
There was a problem hiding this comment.
That test code seem to be not needed anymore.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
__core.Array.eachAs an example,
is now lowered as