@@ -523,14 +523,20 @@ Type TypeBase::getSuperclassForDecl(const ClassDecl *baseClass,
523523 t = t->getSuperclass (useArchetypes);
524524 }
525525
526- #ifndef NDEBUG
527- auto *currentClass = getConcreteTypeForSuperclassTraversing (this )
528- ->getClassOrBoundGenericClass ();
529- assert (baseClass->isSuperclassOf (currentClass) &&
530- " no inheritance relationship between given classes" );
531- #endif
532-
533- return ErrorType::get (this );
526+ if (CONDITIONAL_ASSERT_enabled ()) {
527+ auto *currentClass = getConcreteTypeForSuperclassTraversing (this )
528+ ->getClassOrBoundGenericClass ();
529+ ASSERT (baseClass->isSuperclassOf (currentClass) &&
530+ " no inheritance relationship between given classes" );
531+ }
532+
533+ // We can end up here if the AST is invalid, because then
534+ // getSuperclassDecl() might resolve to a decl, and yet
535+ // getSuperclass() is just an ErrorType. Make sure we still
536+ // return a nominal type as the result though, and not an
537+ // ErrorType, because that's what callers expect.
538+ return baseClass->getDeclaredInterfaceType ()
539+ .subst (SubstitutionMap ())->getCanonicalType ();
534540}
535541
536542SubstitutionMap TypeBase::getContextSubstitutionMap () {
@@ -546,7 +552,7 @@ SubstitutionMap TypeBase::getContextSubstitutionMap() {
546552
547553 Type baseTy (this );
548554
549- assert (!baseTy->hasLValueType () &&
555+ assert (!baseTy->is <LValueType> () &&
550556 !baseTy->is <AnyMetatypeType>() &&
551557 !baseTy->is <ErrorType>());
552558
@@ -628,7 +634,7 @@ TypeBase::getContextSubstitutions(const DeclContext *dc,
628634 assert (dc->isTypeContext ());
629635 Type baseTy (this );
630636
631- assert (!baseTy->hasLValueType () &&
637+ assert (!baseTy->is <LValueType> () &&
632638 !baseTy->is <AnyMetatypeType>() &&
633639 !baseTy->is <ErrorType>());
634640
0 commit comments