Skip to content

Conversation

@SuperUserDone
Copy link
Contributor

This commit solves an issue where lambdas incorrectly capture variables that aren't used within the lambda. As an example, for the given code, the method parameter x and Bar.this are captured into the lambda. Only baz should be captured into the lambda.

package simple.pkg

class Bar {
    fun foo(x: String) {
        val baz: String = "BAZ"
        1.let { println(baz) }
    }
}

@SuperUserDone SuperUserDone requested a review from ml86 January 13, 2026 14:29
@SuperUserDone SuperUserDone marked this pull request as ready for review January 13, 2026 14:29
capturedNodeContext.typeFullName,
closureBinding.closureBindingId
)
scope.addToScope(capturedNodeContext.name, node)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the unfiltered locals get added to the scope. I am no expert in the kt2cpg frontend either but this does not look right.

Copy link
Contributor Author

@SuperUserDone SuperUserDone Jan 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will get back to you on this. AFIK this should not be an issue, as locals are not directly added from the scope to the cpg, but would need to dive deeper to confirm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants