diff options
author | Manoj Palat | 2020-12-09 06:28:40 +0000 |
---|---|---|
committer | Manoj Palat | 2020-12-09 06:28:40 +0000 |
commit | d39f211624807d87052626db1631c06f6520162a (patch) | |
tree | 6a3e107a6092a953725fe0356ca7b6bcf9d1e168 | |
parent | fafd269dae13c7fca9ed84d46098d2501ed6b5b5 (diff) | |
download | eclipse.jdt.core-d39f211624807d87052626db1631c06f6520162a.tar.gz eclipse.jdt.core-d39f211624807d87052626db1631c06f6520162a.tar.xz eclipse.jdt.core-d39f211624807d87052626db1631c06f6520162a.zip |
Change-Id: Ia21c408935b472b9629405afdd01ca229a9a6f13
Signed-off-by: Manoj Palat <manpalat@in.ibm.com>
2 files changed, 37 insertions, 3 deletions
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java index 3de36e3913..8ae72c218c 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SealedTypes15Tests.java @@ -31,7 +31,7 @@ public class SealedTypes15Tests extends AbstractRegressionTest9 { static { // TESTS_NUMBERS = new int [] { 40 }; // TESTS_RANGE = new int[] { 1, -1 }; -// TESTS_NAMES = new String[] { "testBug568428"}; +// TESTS_NAMES = new String[] { "testBug569522"}; } public static Class<?> testClass() { @@ -5513,4 +5513,32 @@ public class SealedTypes15Tests extends AbstractRegressionTest9 { "The type Y that implements a sealed interface X should be a permitted subtype of X\n" + "----------\n"); } + public void testBug569522_001() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " sealed interface Foo<T> permits Bar { }\n"+ + " final class Bar<T> implements Foo<T> { }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(\"\");\n"+ + " }\n"+ + "}", + }, + ""); + } + public void testBug569522_002() throws IOException, ClassFormatException { + runConformTest( + new String[] { + "X.java", + "public class X {\n"+ + " sealed class Foo<T> permits Bar { }\n"+ + " final class Bar<T> extends Foo<T> { }\n"+ + " public static void main(String[] args) {\n"+ + " System.out.println(\"\");\n"+ + " }\n"+ + "}", + }, + ""); + } } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java index 867fcf92c8..4a475f532e 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java @@ -1185,6 +1185,7 @@ private void checkPermitsInType() { continue; if (this.isClass()) { ReferenceBinding permSuperType = permittedType.superclass(); + permSuperType = getActualType(permSuperType); if (!TypeBinding.equalsEquals(this, permSuperType)) { this.scope.problemReporter().sealedNotDirectSuperClass(permittedType, permittedTypeRef, this); continue; @@ -1194,6 +1195,7 @@ private void checkPermitsInType() { boolean foundSuperInterface = false; if (permSuperInterfaces != null) { for (ReferenceBinding psi : permSuperInterfaces) { + psi = getActualType(psi); if (TypeBinding.equalsEquals(this, psi)) { foundSuperInterface = true; break; @@ -1208,6 +1210,10 @@ private void checkPermitsInType() { } return; } + +private ReferenceBinding getActualType(ReferenceBinding ref) { + return ref.isParameterizedType() || ref.isRawType() ? ref.actualType(): ref; +} public List<SourceTypeBinding> collectAllTypeBindings(TypeDeclaration typeDecl, CompilationUnitScope unitScope) { class TypeBindingsCollector extends ASTVisitor { List<SourceTypeBinding> types = new ArrayList<>(); @@ -1247,10 +1253,10 @@ private boolean checkPermitsAndAdd(ReferenceBinding superType, List<SourceTypeBi || superType.equals(this.scope.getJavaLangObject())) return true; if (superType.isSealed()) { - if (superType.isParameterizedType() || superType.isRawType()) - superType = superType.actualType(); + superType = getActualType(superType); ReferenceBinding[] superPermittedTypes = superType.permittedTypes(); for (ReferenceBinding permittedType : superPermittedTypes) { + permittedType = getActualType(permittedType); if (permittedType.isValidBinding() && TypeBinding.equalsEquals(this, permittedType)) return true; } |