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

A sealed interface with generic causes IllegalStateException #3024

Merged
merged 1 commit into from
Oct 1, 2024

Conversation

srikanth-sankaran
Copy link
Contributor

@srikanth-sankaran srikanth-sankaran commented Sep 27, 2024

What it does

Author checklist

@srikanth-sankaran srikanth-sankaran added this to the 4.34 M2 milestone Oct 1, 2024
@srikanth-sankaran srikanth-sankaran merged commit b88a5b3 into eclipse-jdt:master Oct 1, 2024
10 checks passed
@srikanth-sankaran srikanth-sankaran deleted the Issue3009 branch October 1, 2024 10:48
Copy link
Contributor

@stephan-herrmann stephan-herrmann left a comment

Choose a reason for hiding this comment

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

@srikanth-sankaran some questions fyi.

Generally, we seem to be converging based on the understanding that no unchecked cast is allowed and hence all type parameters not determined from the super type must be substituted with wildcards, indeed.

do {
if (current.kind() == Binding.GENERIC_TYPE) {
for (TypeVariableBinding tvb : current.typeVariables()) {
map.put(tvb, null);
Copy link
Contributor

Choose a reason for hiding this comment

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

How would anyone observe the effect of this put()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would anyone observe the effect of this put()?

Isn't it more pertinent to ask "How would anyone observe the effect of this do while loop?" :)

So yes it would seem the entire enclosing do {} while could be gotten rid of - which I will do along with anymore follow up actions on behalf of #3038

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How would anyone observe the effect of this put()?

PR #3149 addresses this review comment, thanks!


// Step 2: Collect substitutes
current = this;
TypeBinding sooper = pt.findSuperTypeOriginatingFrom(this);
Copy link
Contributor

Choose a reason for hiding this comment

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

Splendid naming! 🤣

if (current.isParameterizedType()) {
for (int i = 0, length = sooper.typeArguments().length; i < length; i++) {
TypeBinding t = sooper.typeArguments()[i];
if (t instanceof TypeVariableBinding tvb) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This would also capture capture bindings (pun intended), but super types aren't captured, right?
So what would happen when a wildcard is used? Should you need to call isTypeArgumentContainedBy() instead of testing equality?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This would also capture capture bindings (pun intended), but super types aren't captured, right? So what would happen when a wildcard is used? Should you need to call isTypeArgumentContainedBy() instead of testing equality?

I don't know. Let me know if you are able to construct a test case - we could address any issues in #3038

@srikanth-sankaran
Copy link
Contributor Author

@srikanth-sankaran some questions fyi.

Generally, we seem to be converging based on the understanding that no unchecked cast is allowed and hence all type parameters not determined from the super type must be substituted with wildcards, indeed.

Great! Forbidding unchecked casts intuitively make complete sense since control flow may enter the associated block with the wrong type otherwise. Your reference to 14.30.3 and 5.7 elsewhere is bang on as far as the unchecked cast is concerned - thanks.

WRT #2656 - I seem to have anticipated the introduction of a new context - the testing context - I had named it ExpressionContext.INSTANCEOF_CONTEXT but on HEAD it is renamed by JEP 455 work to be ExpressionContext.TESTING_CONTEXT (as it should be)

@srikanth-sankaran
Copy link
Contributor Author

Generally speaking it hurts that we have poor coverage here. The present implementation of PTB.permittedTypes() uses observed substitutes as being the SAME as the type variables... (my vocabulary may be loose)

@srikanth-sankaran
Copy link
Contributor Author

@srikanth-sankaran some questions fyi.

Generally, we seem to be converging based on the understanding that no unchecked cast is allowed and hence all type parameters not determined from the super type must be substituted with wildcards, indeed.

To make matters complicated we have a regression in unchecked cast reporting - see #1802 that causes some problems in this area: #1735
I am taking up this now - sorry for deferring the grammar changes study to next week. I am fighting a cluster of issues in switches and sealed types and its helps to stay in context.

stephan-herrmann added a commit to stephan-herrmann/eclipse.jdt.core that referenced this pull request Oct 23, 2024
+ uses findSubtypeCorrespondingTo() extracted from eclipse-jdt#3024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants