Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,22 @@ private void validateTypeHierarchy(String desc, XType type, Set<XTypeName> visit
.forEach(typeArg -> validateTypeHierarchy("type argument", typeArg, visited));
type.getSuperTypes()
.forEach(supertype -> validateTypeHierarchy("supertype", supertype, visited));

// XType.getSuperTypes() misses some error types due to a bug in Javac that causes error
// types to be excluded from the supertype list (b/444278301). To work around this, we
// additionally check XTypeElement.getSuperClass() and XTypeElement.getSuperInterfaces()
// to ensure we catch them.
// TODO(b/444278301): Remove this workaround once this Javac bug is fixed.
XTypeElement typeElement = type.getTypeElement();
if (typeElement != null) {
if (typeElement.getSuperClass() != null) {
validateTypeHierarchy("supertype", typeElement.getSuperClass(), visited);
}
typeElement
.getSuperInterfaces()
.forEach(
superInterface -> validateTypeHierarchy("supertype", superInterface, visited));
}
} else if (isTypeVariable(type)) {
asTypeVariable(type)
.getUpperBounds()
Expand Down Expand Up @@ -617,6 +633,7 @@ private ValidationException append(XExecutableType type) {
Ascii.toLowerCase(getKindName(type)),
XExecutableTypes.toStableString(type)));
}

/**
* Appends a message for the given annotation and returns this instance of {@link
* ValidationException}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -653,11 +653,6 @@ public void invalidSupertypeInClass() {
"class Foo : MissingType"),
(processingEnv, superficialValidation) -> {
XTypeElement foo = processingEnv.findTypeElement("test.Foo");
if (processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC) {
// TODO: b/444278301 - Javac's model is missing the error types.
superficialValidation.validateTypeHierarchyOf("type", foo, foo.getType());
return;
}
ValidationException exception =
assertThrows(
ValidationException.KnownErrorType.class,
Expand Down Expand Up @@ -686,11 +681,6 @@ public void invalidSupertypeInInterface() {
"interface Foo : MissingType"),
(processingEnv, superficialValidation) -> {
XTypeElement foo = processingEnv.findTypeElement("test.Foo");
if (processingEnv.getBackend() == XProcessingEnv.Backend.JAVAC) {
// TODO: b/444278301 - Javac's model is missing the error types.
superficialValidation.validateTypeHierarchyOf("type", foo, foo.getType());
return;
}
ValidationException exception =
assertThrows(
ValidationException.KnownErrorType.class,
Expand Down Expand Up @@ -723,12 +713,6 @@ public void invalidSuperInterfaceInTypeHierarchy() {
"class Baz : MissingType {}"),
(processingEnv, superficialValidation) -> {
XTypeElement foo = processingEnv.findTypeElement("test.Foo");
if (isKAPT(processingEnv)) {
// https://youtrack.jetbrains.com/issue/KT-34193/Kapt-CorrectErrorTypes-doesnt-work-for-generics
// There's no way to work around this bug in KAPT so validation doesn't catch this case.
superficialValidation.validateTypeHierarchyOf("type", foo, foo.getType());
return;
}
ValidationException exception =
assertThrows(
ValidationException.KnownErrorType.class,
Expand Down Expand Up @@ -772,13 +756,6 @@ public void invalidSuperInterfaceInArrayTypeHierarchy() {
(processingEnv, superficialValidation) -> {
XTypeElement outerElement = processingEnv.findTypeElement("test.Outer");
XMethodElement getFooMethod = outerElement.getDeclaredMethods().get(0);
if (isKAPT(processingEnv)) {
// https://youtrack.jetbrains.com/issue/KT-34193/Kapt-CorrectErrorTypes-doesnt-work-for-generics
// There's no way to work around this bug in KAPT so validation doesn't catch this case.
superficialValidation.validateTypeHierarchyOf(
"return type", getFooMethod, getFooMethod.getReturnType());
return;
}
ValidationException exception =
assertThrows(
ValidationException.KnownErrorType.class,
Expand Down
Loading