[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: https://github.com/swiftlang/swift/issues/77644
This commit is contained in:
Pavel Yaskevich
2024-11-15 11:10:48 -08:00
parent e7a82901b9
commit 30c196118e
2 changed files with 8 additions and 4 deletions

View File

@@ -13936,6 +13936,13 @@ ConstraintSystem::simplifyExplicitGenericArgumentsConstraint(
} else {
// If the overload hasn't been resolved, we can't simplify this constraint.
auto overloadLocator = getCalleeLocator(getConstraintLocator(locator));
// If there was a problem resolving specialization expression
// it would be diagnosted as invalid AST node.
if (overloadLocator->directlyAt<ErrorExpr>()) {
return shouldAttemptFixes() ? SolutionKind::Error : SolutionKind::Solved;
}
auto selectedOverload = findSelectedOverloadFor(overloadLocator);
if (!selectedOverload)
return formUnsolved();

View File

@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown
// RUN: %target-typecheck-verify-swift
// rdar://139913219 - Make sure we don't crash.
@@ -6,9 +6,6 @@ func bar(_ x: Int.Type, _: Int) {}
func bar<T>(_ x: T.Type, _: Int) {}
func foo() {
// FIXME: We shouldn't be failing to produce a diagnostic.
// Once resolved, remove '-verify-ignore-unknown'
bar(X<Int?>.self, .zero)
// expected-error@-1 {{cannot find 'X' in scope}}
// expected-error@-2 {{failed to produce diagnostic for expression}}
}