mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Sema: Fix a couple of crash-on-invalid problems with class inheritance
It is possible for ClassDecl::getSuperclassDecl() to succeed but for ClassDecl::getSuperclass() to fail. This happens if the superclass is a generic type and one of the generic arguments could not be resolved, or does not satisfy the generic requirements, for example; in that case, a BoundGenericType cannot be formed. In a couple of places we were not prepared for this possibility. Let's recover by making judicious use of ErrorType. Fixes <rdar://problem/73169149>.
This commit is contained in:
@@ -62,6 +62,12 @@ Expr *swift::buildSelfReference(VarDecl *selfDecl,
|
||||
selfTy = metaTy->getInstanceType();
|
||||
}
|
||||
selfTy = selfTy->getSuperclass();
|
||||
if (!selfTy) {
|
||||
// Error recovery path. We end up here if getSuperclassDecl() succeeds
|
||||
// but getSuperclass() fails (because, for instance, a generic parameter
|
||||
// of a generic nominal type cannot be resolved).
|
||||
selfTy = ErrorType::get(ctx);
|
||||
}
|
||||
if (isMetatype)
|
||||
selfTy = MetatypeType::get(selfTy);
|
||||
|
||||
@@ -70,7 +76,7 @@ Expr *swift::buildSelfReference(VarDecl *selfDecl,
|
||||
|
||||
// If no conversion type was specified, or we're already at that type, we're
|
||||
// done.
|
||||
if (!convertTy || convertTy->isEqual(selfTy))
|
||||
if (!convertTy || convertTy->isEqual(selfTy) || selfTy->is<ErrorType>())
|
||||
return superRef;
|
||||
|
||||
// Insert the appropriate expr to handle the upcast.
|
||||
|
||||
Reference in New Issue
Block a user