Skip to content

Commit

Permalink
[CSSimplify] Handle invalid type specializations
Browse files Browse the repository at this point in the history
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: swiftlang#77644
  • Loading branch information
xedin committed Nov 15, 2024
1 parent e7a8290 commit 30c1961
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
7 changes: 7 additions & 0 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
5 changes: 1 addition & 4 deletions test/Constraints/rdar139913219.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
// RUN: %target-typecheck-verify-swift -verify-ignore-unknown
// RUN: %target-typecheck-verify-swift

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

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}}
}

0 comments on commit 30c1961

Please sign in to comment.