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 @@ -111,9 +111,17 @@ Optional<SelectedOverload> FailureDiagnostic::getChoiceFor(Expr *expr) const {
111
111
}
112
112
113
113
Type RequirementFailure::getOwnerType () const {
114
- return getType (getRawAnchor ())
115
- ->getInOutObjectType ()
116
- ->getMetatypeInstanceType ();
114
+ auto *anchor = getRawAnchor ();
115
+
116
+ // If diagnostic is anchored at assignment expression
117
+ // it means that requirement failure happend while trying
118
+ // to convert source to destination, which means that
119
+ // owner type is actually not an assignment expression
120
+ // itself but its source.
121
+ if (auto *assignment = dyn_cast<AssignExpr>(anchor))
122
+ anchor = assignment->getSrc ();
123
+
124
+ return getType (anchor)->getInOutObjectType ()->getMetatypeInstanceType ();
117
125
}
118
126
119
127
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