mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CodeCompletion] Protect against a couple of null Types
Fix two crashes related to unresolved-member completion where either the EnumDecl itself is missing, or its elements have not been type-checked. Incidentally, resolve the type of the enum elements in the case where I have observed this happening. rdar://problem/26860249
This commit is contained in:
@@ -2621,6 +2621,7 @@ public:
|
||||
(EED->hasAccessibility() && !EED->isAccessibleFrom(CurrDeclContext)) ||
|
||||
shouldHideDeclFromCompletionResults(EED))
|
||||
return;
|
||||
|
||||
CommandWordsPairs Pairs;
|
||||
CodeCompletionResultBuilder Builder(
|
||||
Sink,
|
||||
@@ -2633,14 +2634,18 @@ public:
|
||||
Builder.addTextChunk(EED->getName().str());
|
||||
if (EED->hasArgumentType())
|
||||
addPatternFromType(Builder, EED->getArgumentType());
|
||||
Type EnumType = EED->getType();
|
||||
|
||||
// Enum element is of function type such as EnumName.type -> Int ->
|
||||
// EnumName; however we should show Int -> EnumName as the type
|
||||
if (auto FuncType = EED->getType()->getAs<AnyFunctionType>()) {
|
||||
EnumType = FuncType->getResult();
|
||||
Type EnumType;
|
||||
if (EED->hasType()) {
|
||||
EnumType = EED->getType();
|
||||
if (auto FuncType = EnumType->getAs<AnyFunctionType>()) {
|
||||
EnumType = FuncType->getResult();
|
||||
}
|
||||
}
|
||||
addTypeAnnotation(Builder, EnumType);
|
||||
if (EnumType)
|
||||
addTypeAnnotation(Builder, EnumType);
|
||||
}
|
||||
|
||||
void addKeyword(StringRef Name, Type TypeAnnotation,
|
||||
@@ -2936,7 +2941,10 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
bool handleEnumElement(Decl *D, DeclVisibilityKind Reason) {
|
||||
bool handleEnumElement(ValueDecl *D, DeclVisibilityKind Reason) {
|
||||
if (!D->hasType())
|
||||
TypeResolver->resolveDeclSignature(D);
|
||||
|
||||
if (auto *EED = dyn_cast<EnumElementDecl>(D)) {
|
||||
addEnumElementRef(EED, Reason, /*HasTypeContext=*/true);
|
||||
return true;
|
||||
@@ -2944,6 +2952,8 @@ public:
|
||||
llvm::DenseSet<EnumElementDecl *> Elements;
|
||||
ED->getAllElements(Elements);
|
||||
for (auto *Ele : Elements) {
|
||||
if (!Ele->hasType())
|
||||
TypeResolver->resolveDeclSignature(Ele);
|
||||
addEnumElementRef(Ele, Reason, /*HasTypeContext=*/true);
|
||||
}
|
||||
return true;
|
||||
@@ -3655,7 +3665,8 @@ public:
|
||||
LookupByName Lookup(*this, FuncNames);
|
||||
lookupVisibleDecls(Lookup, CurrDeclContext, TypeResolver.get(), true);
|
||||
if (HasReturn)
|
||||
Lookup.unboxType(getReturnTypeFromContext(CurrDeclContext));
|
||||
if (auto ReturnType = getReturnTypeFromContext(CurrDeclContext))
|
||||
Lookup.unboxType(ReturnType);
|
||||
}
|
||||
|
||||
static bool getPositionInTupleExpr(DeclContext &DC, Expr *Target,
|
||||
|
||||
Reference in New Issue
Block a user