Skip to content

Commit 65a452f

Browse files
authored
Merge pull request #22689 from davezarzycki/fix_overloaded_generics_crash
[Sema] NFC: fix assert-only crasher with overloaded generics
2 parents 52aa243 + 51ef3c0 commit 65a452f

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@ ValueDecl *RequirementFailure::getDeclRef() const {
146146
}
147147

148148
if (auto *AE = dyn_cast<CallExpr>(anchor)) {
149-
assert(isa<TypeExpr>(AE->getFn()));
149+
// NOTE: In valid code, the function can only be a TypeExpr
150+
assert(isa<TypeExpr>(AE->getFn()) ||
151+
isa<OverloadedDeclRefExpr>(AE->getFn()));
150152
ConstraintLocatorBuilder ctor(locator);
151153
locator = cs.getConstraintLocator(
152154
ctor.withPathElement(PathEltKind::ApplyFunction)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: not %target-swift-frontend %s -typecheck
2+
3+
protocol A {}
4+
protocol B {}
5+
6+
struct X : A {}
7+
struct Y : B {}
8+
9+
struct G<T:A> { var v : T }
10+
struct G<T:B> { var v : T }
11+
12+
let a = G(v: X())
13+
let b = G(v: Y())

0 commit comments

Comments
 (0)