Skip to content

Commit 30c1961

Browse files
committed
[CSSimplify] Handle invalid type specializations
If the base type of the specialization is invalid, the AST node is going to be replaced with `ErrorExpr`. We need to handle that gracefully when attempting to apply specialization in such situations. Resolves: #77644
1 parent e7a8290 commit 30c1961

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13936,6 +13936,13 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
1393613936
} else {
1393713937
// If the overload hasn't been resolved, we can't simplify this constraint.
1393813938
auto overloadLocator = getCalleeLocator(getConstraintLocator(locator));
13939+
13940+
// If there was a problem resolving specialization expression
13941+
// it would be diagnosted as invalid AST node.
13942+
if (overloadLocator->directlyAt<ErrorExpr>()) {
13943+
return shouldAttemptFixes() ? SolutionKind::Error : SolutionKind::Solved;
13944+
}
13945+
1393913946
auto selectedOverload = findSelectedOverloadFor(overloadLocator);
1394013947
if (!selectedOverload)
1394113948
return formUnsolved();

test/Constraints/rdar139913219.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown
1+
// RUN: %target-typecheck-verify-swift
22

33
// rdar://139913219 - Make sure we don't crash.
44

55
func bar(_ x: Int.Type, _: Int) {}
66
func bar<T>(_ x: T.Type, _: Int) {}
77

88
func foo() {
9-
// FIXME: We shouldn't be failing to produce a diagnostic.
10-
// Once resolved, remove '-verify-ignore-unknown'
119
bar(X<Int?>.self, .zero)
1210
// expected-error@-1 {{cannot find 'X' in scope}}
13-
// expected-error@-2 {{failed to produce diagnostic for expression}}
1411
}

0 commit comments

Comments
 (0)