Skip to content

Commit 51ef3c0

Browse files
committed
[Sema] NFC: fix assert-only crasher with overloaded generics
1 parent 0fe7e14 commit 51ef3c0

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
@@ -136,7 +136,9 @@ ValueDecl *RequirementFailure::getDeclRef() const {
136136
auto *anchor = getRawAnchor();
137137
auto *locator = cs.getConstraintLocator(anchor);
138138
if (auto *AE = dyn_cast<CallExpr>(anchor)) {
139-
assert(isa<TypeExpr>(AE->getFn()));
139+
// NOTE: In valid code, the function can only be a TypeExpr
140+
assert(isa<TypeExpr>(AE->getFn()) ||
141+
isa<OverloadedDeclRefExpr>(AE->getFn()));
140142
ConstraintLocatorBuilder ctor(locator);
141143
locator = cs.getConstraintLocator(
142144
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)