Skip to content

Commit 197046c

Browse files
committed
[CodeCompletion] Don’t crash if constructors in member lookup have an error type
1 parent b22c200 commit 197046c

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8359,12 +8359,16 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
83598359

83608360
// Only try and favor monomorphic unary initializers.
83618361
if (!ctor->isGenericContext()) {
8362-
auto args = ctor->getMethodInterfaceType()
8363-
->castTo<FunctionType>()->getParams();
8364-
if (args.size() == 1 && !args[0].hasLabel() &&
8365-
args[0].getPlainType()->isEqual(favoredType)) {
8366-
if (!isDeclUnavailable(decl, memberLocator))
8367-
result.FavoredChoice = result.ViableCandidates.size();
8362+
if (!ctor->getMethodInterfaceType()->is<ErrorType>()) {
8363+
// The constructor might have an error type because we don't skip
8364+
// invalid decls for code completion
8365+
auto args = ctor->getMethodInterfaceType()
8366+
->castTo<FunctionType>()->getParams();
8367+
if (args.size() == 1 && !args[0].hasLabel() &&
8368+
args[0].getPlainType()->isEqual(favoredType)) {
8369+
if (!isDeclUnavailable(decl, memberLocator))
8370+
result.FavoredChoice = result.ViableCandidates.size();
8371+
}
83688372
}
83698373
}
83708374
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
public struct AnyError {
2+
3+
public init(_ error: Swift.
4+
5+
extension AnyError {
6+
public static func error(from error: Error) -> AnyError {
7+
return AnyError(error)#^COMPLETE^#
8+
}
9+
}

0 commit comments

Comments
 (0)