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

fix: print necessary parentheses when accessing a new array directly #4239

Merged
merged 4 commits into from
Oct 22, 2021

Conversation

SirYwell
Copy link
Collaborator

Previously, a statement like int a = (new int[10])[1]; was printed like int a = new int[10][1];. This won't compile anymore as the types aren't compatible.

While I hope I'll never come across such code anywhere, I thought it would be worth to fix it.

@SirYwell SirYwell changed the title wip: fix: print necessary parentheses when accessing a new array directly review: fix: print necessary parentheses when accessing a new array directly Oct 19, 2021
CtModel model = SpoonTestHelpers.createModelFromString(code, 8);
CtType<?> first = model.getAllTypes().iterator().next();
assertThat(first.toString(), containsString(line));
CtCodeSnippetStatement statement = launcher.getFactory().createCodeSnippetStatement(line);
Copy link
Collaborator

Choose a reason for hiding this comment

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

if you pretty-print a CtCodeSnippetStatement, it's the input line, so the assert is useless. you have to call compile first to transform the CtCodeSnippetStatement into an AST

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh yeah, that wasn't meant to end up there. Thanks for catching it.

@monperrus
Copy link
Collaborator

LGTM, needs to fix conflicts

@SirYwell SirYwell force-pushed the fix/new-array-access branch from b3adc93 to 83a66e5 Compare October 22, 2021 07:52
@SirYwell
Copy link
Collaborator Author

Rebased (and removed unused code I added before)

@monperrus monperrus changed the title review: fix: print necessary parentheses when accessing a new array directly fix: print necessary parentheses when accessing a new array directly Oct 22, 2021
@monperrus monperrus merged commit 68fed6a into INRIA:master Oct 22, 2021
@monperrus
Copy link
Collaborator

Cool, nice Friday contribution :)

@SirYwell SirYwell deleted the fix/new-array-access branch October 22, 2021 08:21
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