Skip to content

Conversation

@rajshivu
Copy link

@rajshivu rajshivu commented Feb 9, 2026

Updated CreateASTVisitor to map refinement variables '_' and 'return' to '$result' to prevent conflicts.
Verified by manual test in ReturnRefinementTest.java.
firstos

Copy link
Collaborator

@rcosta358 rcosta358 left a comment

Choose a reason for hiding this comment

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

Hi @rajshivu,
This is not really what we were looking for. Your approach replaces the variables return and _ with $result, which is incorrect and causes the tests to fail.

To allow $result to represent return values of methods, you need to modify the grammar to allow identifiers to start with $, substitute the variable $result with _ (similarly to return), and finally add some tests to check if your implementation is correct.

Copy link
Collaborator

@rcosta358 rcosta358 left a comment

Choose a reason for hiding this comment

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

Also, if you have any suggestions other than $result, which is not very idiomatic for Java, feel free to let us know!

@rajshivu
Copy link
Author

Hi @rcosta358 ,
Thank you for the clarification - that makes sense. You’re right, my initial approach was too naive and incorrectly replaced return and _ directly with $result, which explains the failing tests.

Based on your feedback, I understand the correct direction is to:

  1. Extend the grammar to allow identifiers starting with $.
  2. Treat $result as a syntactic alias and internally substitute it with _ (similarly to how return is handled today).
  3. Add proper tests to validate that $result, _, and return behave consistently.

I’ll update the implementation accordingly and push a revised PR.
Also, I agree that $result may not be the most idiomatic Java-style identifier — I’ll think about alternative suggestions and share them if I find a better fit.

Thanks again for the guidance, this was very helpful.

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.

2 participants