[CodeCompletion] Don’t crash if constructors in member lookup have an error type

This commit is contained in:
Alex Hoppen
2023-02-22 22:33:06 +01:00
parent 470dcde915
commit 46f5119113
2 changed files with 23 additions and 6 deletions

View File

@@ -9171,12 +9171,17 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
// Only try and favor monomorphic unary initializers. // Only try and favor monomorphic unary initializers.
if (!ctor->isGenericContext()) { if (!ctor->isGenericContext()) {
auto args = ctor->getMethodInterfaceType() if (!ctor->getMethodInterfaceType()->hasError()) {
->castTo<FunctionType>()->getParams(); // The constructor might have an error type because we don't skip
if (args.size() == 1 && !args[0].hasLabel() && // invalid decls for code completion
args[0].getPlainType()->isEqual(favoredType)) { auto args = ctor->getMethodInterfaceType()
if (!isDeclUnavailable(decl, memberLocator)) ->castTo<FunctionType>()
result.FavoredChoice = result.ViableCandidates.size(); ->getParams();
if (args.size() == 1 && !args[0].hasLabel() &&
args[0].getPlainType()->isEqual(favoredType)) {
if (!isDeclUnavailable(decl, memberLocator))
result.FavoredChoice = result.ViableCandidates.size();
}
} }
} }
} }

View File

@@ -0,0 +1,12 @@
// Make sure we don't crash
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token COMPLETE
public struct AnyError {
public init(_ error: Swift.
extension AnyError {
public static func error(from error: Error) -> AnyError {
return AnyError(error)#^COMPLETE^#
}
}