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

feature: add support for first class resource in try-with-resource #4371

Merged
merged 10 commits into from
Feb 14, 2022

Conversation

henryhchchc
Copy link
Contributor

This PR fixes #4368.

@henryhchchc henryhchchc force-pushed the try-with-resource-fix branch from 8208bc6 to 3954684 Compare December 21, 2021 07:07
@henryhchchc henryhchchc force-pushed the try-with-resource-fix branch from 3954684 to f373be3 Compare December 21, 2021 07:07
@monperrus
Copy link
Collaborator

Thanks. Adding a new metamodel interface is a significant change in Spoon, which we do cautiously. Could you elaborate on why it's needed?

@henryhchchc
Copy link
Contributor Author

Thanks for working on my PR. I think it is well discussed in issue #4368.

@monperrus
Copy link
Collaborator

@slarse @SirYwell you were involved in the conversation of #4368

WDYT of this PR?

@SirYwell
Copy link
Collaborator

SirYwell commented Jan 6, 2022

It's basically the way I would have done it too.
The only critical point are the breaking changes. Some of the methods could be overloaded instead of replacing them, but others would require a different name...

I think we can also not get rid of the generic parameter in CtResource as long as it extends CtTypedElement, because that would mean that CtLocalVariable<T> indirectly extends both CtTypedElement<T> and CtTypedElement (raw), which isn't allowed.

Maybe it would make sense to remove CtTypedElement from CtResource, that way we can get rid of a lot of <?>. WDYT?

@slarse
Copy link
Collaborator

slarse commented Jan 7, 2022

Essentially what @SirYwell said. We must modify the metamodel here because it's incorrect. We could do it in a less breaking fashion, though. addReasource and removeResource can be overloaded as suggested by @SirYwell. The others can't be overloaded in the way we want, as methods can't be overloaded on return types at all and it's also not possible to overload on type parameters (due to type erasure). So to mostly keep backwards compatibility there, we'd need to add new methods, which will make the interface more awkward.

@slarse
Copy link
Collaborator

slarse commented Feb 2, 2022

@monperrus @MartinWitt We should decide what to do here, @henryhchchc has made a nice contribution and I don't like to see it hanging. This is a reasonable solution to the problem, but it is breaking. We therefore can't incorporate it without a major version bump.

Frankly, I can't see a non-breaking solution to this problem.

@monperrus
Copy link
Collaborator

Agree with you @slarse

@henryhchchc We need test cases to specify this new feature, would you add them?

@henryhchchc
Copy link
Contributor Author

Agree with you @slarse

@henryhchchc We need test cases to specify this new feature, would you add them?

Sorry I am too busy to work on the test cases at this moment. 🥲

@slarse
Copy link
Collaborator

slarse commented Feb 3, 2022

Sorry I am too busy to work on the test cases at this moment. smiling_face_with_tear

@henryhchchc That's entirely OK, it happens to all of us. Evidently it happened to us as we were very slow to provide feedback here :)

We'll put this on hold for the time being. If this becomes urgent for someone else, they can use your PR as a starting point. Otherwise, it will be here when you get some time again.

I'll check back in a while.

@henryhchchc
Copy link
Contributor Author

Hi I added a test case checking whether the try-with-resource statements are correctly parsed.

@xzel23
Copy link
Contributor

xzel23 commented Feb 14, 2022

Hi, IMHO this is a rather important fix (at least for my own project, that's why I comment). I did not look at the new test cases, but I pulled this PR into my own fork of spoon, and it looks good to me: I have try-with-resources both with variable declaration and variable access in my code, and with the PR applied all problems with the latter are fixed while former still work as expected.

@monperrus monperrus changed the title review: fix #4368: add support for try-with-resource statement with variable access review: feature: add support for try-with-resource in metamodel Feb 14, 2022
@monperrus
Copy link
Collaborator

yes, let's finish this one.

added the natural language contracts and a few test lines to fully cover the new code.

I will merge.

thanks a lot @henryhchchc for this valuable contribution.

@monperrus monperrus changed the title review: feature: add support for try-with-resource in metamodel feature: add support for first class resource in try-with-resource Feb 14, 2022
@monperrus monperrus merged commit af5774e into INRIA:master Feb 14, 2022
@henryhchchc henryhchchc deleted the try-with-resource-fix branch February 15, 2022 03:14
@monperrus
Copy link
Collaborator

FYI This PR causes a regression in NpeFix see https://ci.inria.fr/sos/job/npefix/

I'm working on it for restoring backward compatibility

@slarse
Copy link
Collaborator

slarse commented Feb 23, 2022

@monperrus I don't think this can be implemented to be completely non-breaking unless we add a "new api" for the same functionality, see my musings here #4371 (comment)

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] Unable to parse TryWithResourcesStatement when the resource list contains a VariableAccess
5 participants