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: Fix dropping diamonds on constructor calls #3362

Merged
merged 11 commits into from
May 8, 2020

Conversation

slarse
Copy link
Collaborator

@slarse slarse commented May 7, 2020

Fix #3360

This is an attempt to fix the problem discussed in #3360

What I do here is essentially to try to recover the type arguments from the AllocationExpression's expected type. To the best of my knowledge, empty diamonds are only allowed on constructor calls, so I only have an assert that the stack's top element is an AllocationExpression. It shouldn't be possible for it to be anything else.

If the constructor call occurs inside of an unresolved method, or another constructor call, then the AllocationExpression doesn't have an expected type (because it can't be resolved). In that case, I add the new OMITTED_TYPE_ARG_TYPE (name could use some work) to the type argument list so at least Spoon can detect that the constructor is in fact parameterized, and will then print <>.

This appears to work as intended, but I'll be running some more tests locally with my merge tool to see if other issues crop up.

@slarse slarse changed the title WIP: fix: Fix Spoon sometimes dropping <> on constructor calls review: fix: Fix Spoon sometimes dropping <> on constructor calls May 7, 2020
@slarse
Copy link
Collaborator Author

slarse commented May 7, 2020

I'm pretty happy with this now, it appears to work for my purposes. None of the cases where I lost <> seem to happen anymore.

I'm unsure about the use of the OMITTED_TYPE_ARG_TYPE, I'm not certain that's the way things should be done in Spoon, but purely functionally I think this works well.

@monperrus
Copy link
Collaborator

LGTM, will merge.

@monperrus monperrus changed the title review: fix: Fix Spoon sometimes dropping <> on constructor calls fix: Fix dropping diamonds on constructor calls May 8, 2020
@monperrus monperrus merged commit 92ee4ba into INRIA:master May 8, 2020
@monperrus
Copy link
Collaborator

Thanks @slarse well done

@slarse
Copy link
Collaborator Author

slarse commented May 9, 2020

Happy to contribute!

@slarse slarse deleted the issue/3360-fix-dropped-diamonds branch May 28, 2021 10:07
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.

bug: <> dropped from constructor calls to generic types (noclasspath)
2 participants