Skip to content

Commit 50763fc

Browse files
committed
[AST] Re-establish assertion about inheritance relationship in getSuperclassForDecl()
When we fail to find a particular superclass type of a type in ill-formed code, make sure that we were right to look here at all. This re-establishes a check I had recently weakened.
1 parent 7f75914 commit 50763fc

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/AST/Type.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3193,6 +3193,15 @@ Type TypeBase::getSuperclassForDecl(const ClassDecl *baseClass,
31933193
t = t->getSuperclass(useArchetypes);
31943194
}
31953195

3196+
#ifndef NDEBUG
3197+
auto *currentClass = getConcreteTypeForSuperclassTraversing(this)
3198+
->getClassOrBoundGenericClass();
3199+
while (currentClass && currentClass != baseClass)
3200+
currentClass = currentClass->getSuperclassDecl();
3201+
assert(currentClass == baseClass &&
3202+
"no inheritance relationship between given classes");
3203+
#endif
3204+
31963205
return ErrorType::get(this);
31973206
}
31983207

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ Type TypeChecker::resolveTypeInContext(
300300
if (!sig)
301301
return ErrorType::get(Context);
302302
auto superclassType = sig->getSuperclassBound(selfType);
303-
assert(superclassType);
303+
if (!superclassType)
304+
return ErrorType::get(Context);
305+
304306
selfType = superclassType;
305307
}
306308
}

0 commit comments

Comments
 (0)