Skip to content

Commit

Permalink
[Sealed types + switch expression] Internal inconsistency warning at …
Browse files Browse the repository at this point in the history
…compile time and verify error at runtime (eclipse-jdt#2715)

* Fixes eclipse-jdt#2714
  • Loading branch information
srikanth-sankaran authored Jul 17, 2024
1 parent b9cbe94 commit bfd2774
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -731,6 +731,20 @@ public boolean isTypeVariable() {
return true;
}

@Override
public boolean isSealed() {
if (this.superclass != null && this.superclass.isSealed())
return true;

if (this.superInterfaces != null && this.superInterfaces != Binding.NO_SUPERINTERFACES) {
for (int i = 0, length = this.superInterfaces.length; i < length; i++) {
if (this.superInterfaces[i].isSealed())
return true;
}
}
return false;
}

// /**
// * Returns the original type variable for a given variable.
// * Only different from receiver for type variables of generic methods of parameterized types
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,6 @@ public void operandStackSizeInappropriate(ASTNode location) {
ProblemSeverities.Warning,
location.sourceStart,
location.sourceEnd);
throw new AssertionError("Anomalous/Inconsistent operand stack!"); //$NON-NLS-1$
}
public void bytecodeExceeds64KLimit(LambdaExpression location) {
bytecodeExceeds64KLimit(location.binding, location.sourceStart, location.diagnosticsSourceEnd());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8273,4 +8273,34 @@ void newStyle(NUM n) {
"----------\n";
runner.runNegativeTest();
}

// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2714
// [Sealed types + switch expression] Internal inconsistency warning at compile time and verify error at runtime
public void testIssue2714() {
runConformTest(
new String[] {
"X.java",
"""
public interface X {
static <T extends AbstractSealedClass> Integer get(T object) {
return switch (object) {
case ClassB ignored -> 42;
};
}
public abstract sealed class AbstractSealedClass permits ClassB {
}
public final class ClassB extends AbstractSealedClass {
}
public static void main(String[] args) {
System.out.println(get(new ClassB()));
}
}
"""
},
"42");
}
}

0 comments on commit bfd2774

Please sign in to comment.