Skip to content

Commit 46f5119

Browse files
committed
[CodeCompletion] Don’t crash if constructors in member lookup have an error type
1 parent 470dcde commit 46f5119

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9171,12 +9171,17 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
91719171

91729172
// Only try and favor monomorphic unary initializers.
91739173
if (!ctor->isGenericContext()) {
9174-
auto args = ctor->getMethodInterfaceType()
9175-
->castTo<FunctionType>()->getParams();
9176-
if (args.size() == 1 && !args[0].hasLabel() &&
9177-
args[0].getPlainType()->isEqual(favoredType)) {
9178-
if (!isDeclUnavailable(decl, memberLocator))
9179-
result.FavoredChoice = result.ViableCandidates.size();
9174+
if (!ctor->getMethodInterfaceType()->hasError()) {
9175+
// The constructor might have an error type because we don't skip
9176+
// invalid decls for code completion
9177+
auto args = ctor->getMethodInterfaceType()
9178+
->castTo<FunctionType>()
9179+
->getParams();
9180+
if (args.size() == 1 && !args[0].hasLabel() &&
9181+
args[0].getPlainType()->isEqual(favoredType)) {
9182+
if (!isDeclUnavailable(decl, memberLocator))
9183+
result.FavoredChoice = result.ViableCandidates.size();
9184+
}
91809185
}
91819186
}
91829187
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Make sure we don't crash
2+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token COMPLETE
3+
4+
public struct AnyError {
5+
6+
public init(_ error: Swift.
7+
8+
extension AnyError {
9+
public static func error(from error: Error) -> AnyError {
10+
return AnyError(error)#^COMPLETE^#
11+
}
12+
}

0 commit comments

Comments
 (0)