Skip to content

Commit 290bd04

Browse files
committed
[CSDiag] Fix crash related to failures in contextual type requirements
If failed constraint mentions member declaration which is not generic, it means that generic requirements came from context and should not be diagnosed by `diagnoseUnresolvedDotExprTypeRequirementFailure`. Resolved: rdar://problem/45511837
1 parent 3be98d7 commit 290bd04

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,8 @@ diagnoseUnresolvedDotExprTypeRequirementFailure(ConstraintSystem &cs,
12891289
// If we actually resolved the member to use, use it.
12901290
auto loc = cs.getConstraintLocator(UDE, ConstraintLocator::Member);
12911291
auto *member = cs.findResolvedMemberRef(loc);
1292-
if (!member)
1292+
// If the problem is contextual it's diagnosed elsewhere.
1293+
if (!member || !member->getAsGenericContext())
12931294
return false;
12941295

12951296
auto req = member->getAsGenericContext()

test/Constraints/rdar45511837.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
protocol A: RawRepresentable {}
7+
8+
extension A {
9+
static func +(lhs: RawValue, rhs: Self) -> Self {
10+
fatalError()
11+
}
12+
}
13+
14+
class Foo<Bar: NSObject> {
15+
var foobar: Bar {
16+
fatalError()
17+
}
18+
19+
lazy var foo: () -> Void = {
20+
// TODO: improve diagnostic message
21+
_ = self.foobar + nil // expected-error {{'Foo<Bar>' requires that 'Bar' inherit from 'NSObject'}}
22+
}
23+
}

0 commit comments

Comments
 (0)