Skip to content
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

Don't stop iteration on constructor calls, only anonymous subclasses #37

Merged
merged 1 commit into from
Nov 8, 2023

Conversation

knutwannheden
Copy link
Contributor

The lambda support is basically already there. What was missing for the existing LambdaTest test case was that the iteration in LocalVariableDecl#findNearestParentCallable() stopped on any constructor invocation, rather than only when iterating out of the body of an anonymous subclasses.

Fixes: #31

The lambda support is basically already there. What was missing for the existing `LambdaTest` test case was that the iteration in `LocalVariableDecl#findNearestParentCallable()` stopped on any constructor invocation, rather than only when iterating out of the body of an anonymous subclasses.

Fixes: #31
@@ -105,7 +105,7 @@ static Validation<TraitErrors, Callable> findNearestParentCallable(Cursor cursor
while (path.hasNext()) {
Cursor c = path.next();
Tree t = c.getValue();
if (t instanceof J.ClassDeclaration || t instanceof J.NewClass) {
if (t instanceof J.ClassDeclaration || t instanceof J.NewClass && previous != null && ((J.NewClass) t).getBody() == previous.getValue()) {
break;
}
if (t instanceof J.Block && J.Block.isStaticOrInitBlock(c)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also note that in the context of lambdas the body block was erroneously identified as an initializer block. That is fixed by openrewrite/rewrite@69b48c8

Copy link
Contributor

Choose a reason for hiding this comment

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

Much appreciated! Thanks for fixing!

@knutwannheden knutwannheden merged commit 1a92087 into main Nov 8, 2023
@knutwannheden knutwannheden deleted the anonymous-subclasses branch November 8, 2023 22:06
@knutwannheden
Copy link
Contributor Author

@JLLeitschuh I went ahead and merged the PR, as it isn't clear to me to what extent you are available to review PRs. But I will be happy to fix any mistakes you detect in my PR.

@JLLeitschuh
Copy link
Contributor

My biggest thing is just ensuring that tests exist to cover changes. It looks like you've done that, which I appreciate!

Thanks for the improvements! 🙂🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

VarAccess raises TraitErrorsException for accesses in lambda expressions
2 participants