diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 5640716a766ff..09676d993eebe 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -906,9 +906,13 @@ Type TypeBase::lookThroughAllOptionalTypes(SmallVectorImpl &optionals){ } unsigned int TypeBase::getOptionalityDepth() { - SmallVector types; - lookThroughAllOptionalTypes(types); - return types.size(); + Type type(this); + unsigned int depth = 0; + while (auto objType = type->getOptionalObjectType()) { + type = objType; + ++depth; + } + return depth; } Type TypeBase::stripConcurrency(bool recurse, bool dropGlobalActor) {