Skip to content

Commit 92dbcb1

Browse files
committed
[CSDiagnostics] Use simplified locator to find owner type of a requirement failure
Only simplified locator points to the right underlying expression. Resolves: rdar://116122902 (cherry picked from commit b3da15e)
1 parent 80e98ca commit 92dbcb1

File tree

3 files changed

+9
-10
lines changed

3 files changed

+9
-10
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,7 @@ bool FailureDiagnostic::conformsToKnownProtocol(
216216
}
217217

218218
Type RequirementFailure::getOwnerType() const {
219-
auto anchor = getRawAnchor();
220-
219+
auto anchor = getAnchor();
221220
// If diagnostic is anchored at assignment expression
222221
// it means that requirement failure happened while trying
223222
// to convert source to destination, which means that

test/Generics/conditional_conformances.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func existential_good<T: P1>(_: T.Type) {
353353
}
354354

355355
func existential_bad<T>(_: T.Type) {
356-
_ = Free<T>() as P2 // expected-error{{protocol 'P2' requires that 'T' conform to 'P1'}}
356+
_ = Free<T>() as P2 // expected-error{{generic struct 'Free' requires that 'T' conform to 'P1'}}
357357
}
358358

359359
// rdar://problem/35837054

test/Generics/conditional_conformances_literals.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func arraySameType() {
4545

4646
let _: SameType = arrayWorks as SameType
4747
let _: SameType = arrayFails as SameType
48-
// expected-error@-1 {{protocol 'SameType' requires the types 'Fails' and 'Works' be equivalent}}
48+
// expected-error@-1 {{generic struct 'Array' requires the types 'Fails' and 'Works' be equivalent}}
4949
}
5050

5151
func dictionarySameType() {
@@ -70,7 +70,7 @@ func dictionarySameType() {
7070

7171
let _: SameType = dictWorks as SameType
7272
let _: SameType = dictFails as SameType
73-
// expected-error@-1 {{protocol 'SameType' requires the types 'Fails' and 'Works' be equivalent}}
73+
// expected-error@-1 {{generic struct 'Dictionary' requires the types 'Fails' and 'Works' be equivalent}}
7474
}
7575

7676
func arrayConforms() {
@@ -91,11 +91,11 @@ func arrayConforms() {
9191

9292
let _: Conforms = [works] as Conforms
9393
let _: Conforms = [fails] as Conforms
94-
// expected-error@-1 {{protocol 'Conforms' requires that 'Fails' conform to 'Conforms'}}
94+
// expected-error@-1 {{generic struct 'Array' requires that 'Fails' conform to 'Conforms'}}
9595

9696
let _: Conforms = arrayWorks as Conforms
9797
let _: Conforms = arrayFails as Conforms
98-
// expected-error@-1 {{protocol 'Conforms' requires that 'Fails' conform to 'Conforms'}}
98+
// expected-error@-1 {{generic struct 'Array' requires that 'Fails' conform to 'Conforms'}}
9999
}
100100

101101
func dictionaryConforms() {
@@ -116,11 +116,11 @@ func dictionaryConforms() {
116116

117117
let _: Conforms = [0 : works] as Conforms
118118
let _: Conforms = [0 : fails] as Conforms
119-
// expected-error@-1 {{protocol 'Conforms' requires that 'Fails' conform to 'Conforms'}}
119+
// expected-error@-1 {{generic struct 'Dictionary' requires that 'Fails' conform to 'Conforms'}}
120120

121121
let _: Conforms = dictWorks as Conforms
122122
let _: Conforms = dictFails as Conforms
123-
// expected-error@-1 {{protocol 'Conforms' requires that 'Fails' conform to 'Conforms'}}
123+
// expected-error@-1 {{generic struct 'Dictionary' requires that 'Fails' conform to 'Conforms'}}
124124
}
125125

126126
func combined() {
@@ -133,6 +133,6 @@ func combined() {
133133
// expected-error@-1 {{type 'any Conforms' cannot conform to 'Conforms'}} expected-note@-1 {{only concrete types such as structs, enums and classes can conform to protocols}}
134134

135135
let _: Conforms = [[0: [1 : [fails]] as Conforms]]
136-
// expected-error@-1 {{protocol 'Conforms' requires that 'Fails' conform to 'Conforms'}}
136+
// expected-error@-1 {{generic struct 'Dictionary' requires that 'Fails' conform to 'Conforms'}}
137137
// expected-error@-2 {{type 'any Conforms' cannot conform to 'Conforms'}} expected-note@-2 {{only concrete types such as structs, enums and classes can conform to protocols}}
138138
}

0 commit comments

Comments
 (0)