Skip to content

Commit b0360ce

Browse files
committed
AST: Don't build archetypes with an error type as the superclass
This breaks invariants.
1 parent cb845d8 commit b0360ce

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2020,11 +2020,13 @@ Type GenericSignatureBuilder::PotentialArchetype::getTypeInContext(
20202020
Type superclass = representative->getSuperclass();
20212021
if (superclass && superclass->hasTypeParameter()) {
20222022
if (representative->RecursiveSuperclassType) {
2023-
superclass = ErrorType::get(superclass);
2023+
superclass = Type();
20242024
} else {
20252025
superclass = genericEnv->mapTypeIntoContext(
20262026
superclass,
20272027
builder.getLookupConformanceFn());
2028+
if (superclass->is<ErrorType>())
2029+
superclass = Type();
20282030

20292031
// We might have recursively recorded the archetype; if so, return early.
20302032
// FIXME: This should be detectable before we end up building archetypes.

lib/AST/Type.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,6 +2558,8 @@ CanArchetypeType ArchetypeType::getNew(
25582558
SmallVectorImpl<ProtocolDecl *> &ConformsTo,
25592559
Type Superclass,
25602560
LayoutConstraint Layout) {
2561+
assert(!Superclass || Superclass->getClassOrBoundGenericClass());
2562+
25612563
// Gather the set of protocol declarations to which this archetype conforms.
25622564
ProtocolType::canonicalizeProtocols(ConformsTo);
25632565

@@ -2578,6 +2580,7 @@ ArchetypeType::getNew(const ASTContext &Ctx,
25782580
SmallVectorImpl<ProtocolDecl *> &ConformsTo,
25792581
Type Superclass,
25802582
LayoutConstraint Layout) {
2583+
assert(!Superclass || Superclass->getClassOrBoundGenericClass());
25812584
assert(genericEnvironment && "missing generic environment for archetype");
25822585

25832586
// Gather the set of protocol declarations to which this archetype conforms.

0 commit comments

Comments
 (0)