File tree Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Expand file tree Collapse file tree 2 files changed +35
-3
lines changed Original file line number Diff line number Diff line change @@ -131,9 +131,17 @@ Optional<SelectedOverload> FailureDiagnostic::getChoiceFor(Expr *expr) {
131
131
}
132
132
133
133
Type RequirementFailure::getOwnerType () const {
134
- return getType (getRawAnchor ())
135
- ->getInOutObjectType ()
136
- ->getMetatypeInstanceType ();
134
+ auto *anchor = getRawAnchor ();
135
+
136
+ // If diagnostic is anchored at assignment expression
137
+ // it means that requirement failure happend while trying
138
+ // to convert source to destination, which means that
139
+ // owner type is actually not an assignment expression
140
+ // itself but its source.
141
+ if (auto *assignment = dyn_cast<AssignExpr>(anchor))
142
+ anchor = assignment->getSrc ();
143
+
144
+ return getType (anchor)->getInOutObjectType ()->getMetatypeInstanceType ();
137
145
}
138
146
139
147
const GenericContext *RequirementFailure::getGenericContext () const {
Original file line number Diff line number Diff line change
1
+ // RUN: %target-typecheck-verify-swift
2
+
3
+ protocol ViewDataSource : class {
4
+ func foo< T> ( ) -> [ T ]
5
+ }
6
+
7
+ class View {
8
+ weak var delegate : ViewDataSource ?
9
+ }
10
+
11
+ final class ViewController < T> {
12
+ let view = View ( )
13
+ init ( ) {
14
+ view. delegate = self
15
+ // expected-error@-1 {{generic class 'ViewController' requires the types 'T' and 'String' be equivalent}}
16
+ }
17
+ }
18
+
19
+ extension ViewController : ViewDataSource where T == String {
20
+ // expected-note@-1 {{requirement from conditional conformance of 'ViewController<T>' to 'ViewDataSource'}}
21
+ func foo< T> ( ) -> [ T ] {
22
+ return [ ]
23
+ }
24
+ }
You can’t perform that action at this time.
0 commit comments