Skip to content

Commit 4fa4133

Browse files
committed
Sema: Fix crash with UnresolvedType in coerceExistential()
Fixes <rdar://problem/34357545>.
1 parent 4023105 commit 4fa4133

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

lib/Sema/CSApply.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5484,9 +5484,11 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType,
54845484
Type toInstanceType = toType;
54855485

54865486
// Look through metatypes
5487-
while (fromInstanceType->is<AnyMetatypeType>() &&
5487+
while ((fromInstanceType->is<UnresolvedType>() ||
5488+
fromInstanceType->is<AnyMetatypeType>()) &&
54885489
toInstanceType->is<ExistentialMetatypeType>()) {
5489-
fromInstanceType = fromInstanceType->castTo<AnyMetatypeType>()->getInstanceType();
5490+
if (!fromInstanceType->is<UnresolvedType>())
5491+
fromInstanceType = fromInstanceType->castTo<AnyMetatypeType>()->getInstanceType();
54905492
toInstanceType = toInstanceType->castTo<ExistentialMetatypeType>()->getInstanceType();
54915493
}
54925494

test/Constraints/diagnostics.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,3 +1193,9 @@ func badTypes() {
11931193
// expected-error@-1 {{type of expression is ambiguous without more context}}
11941194
// FIXME: terrible diagnostic
11951195
}
1196+
1197+
// rdar://34357545
1198+
func unresolvedTypeExistential() -> Bool {
1199+
return (Int.self==_{})
1200+
// expected-error@-1 {{ambiguous reference to member '=='}}
1201+
}

validation-test/compiler_crashers/28739-unreachable-executed-at-swift-lib-ast-type-cpp-229.swift renamed to validation-test/compiler_crashers_fixed/28739-unreachable-executed-at-swift-lib-ast-type-cpp-229.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
// See https://swift.org/LICENSE.txt for license information
66
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -emit-ir
8+
// RUN: not %target-swift-frontend %s -emit-ir
99
(Int==_{

0 commit comments

Comments
 (0)