Skip to content

Commit fbd51c0

Browse files
committed
Sema: apply scoping SuppAssocType scoping rule roots
The generic parameter at the root of a DependentMemberType is the main thing we care about in terms of the scoping rule. We have a check for ineffective / invalid inverses in a later phase, so if the suppression on the type member was wrong then we should still raise an error about it.
1 parent 64abbed commit fbd51c0

File tree

3 files changed

+3
-7
lines changed

3 files changed

+3
-7
lines changed

lib/AST/RequirementMachine/ApplyInverses.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ void swift::rewriting::applyInverses(
204204
// func f() where Self: ~Copyable
205205
// }
206206
//
207-
if (representativeGPs.find(canSubject) == representativeGPs.end()) {
207+
auto subjectRoot = canSubject->getDependentMemberRoot()->getCanonicalType();
208+
if (representativeGPs.find(subjectRoot) == representativeGPs.end()) {
208209
errors.push_back(
209210
RequirementError::forInvalidInverseOuterSubject(inverse));
210211
continue;

test/Generics/inverse_assoc_types.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,8 @@ protocol Veggie<A> {
156156
}
157157
protocol Carrot: Veggie
158158
where Self.NeedsCopyable: ~Copyable {} // expected-error {{'Self.NeedsCopyable' required to be 'Copyable' but is marked with '~Copyable'}}
159-
// expected-error @-1{{cannot suppress '~Copyable' on generic parameter 'Self.NeedsCopyable' defined in outer scope}}
160159

161160
protocol CarrotCake: Carrot where Self.A: ~Copyable {} // expected-error {{'Self.A' required to be 'Copyable' but is marked with '~Copyable'}}
162-
// expected-error @-1{{cannot suppress '~Copyable' on generic parameter 'Self.A' defined in outer scope}}
163161

164162
func ex1<Cucumber: ~Copyable, Potato>(_ nc: any Veggie<Cucumber>, c: any Veggie<Potato>) {
165163
reqC(nc.a()) // expected-error {{global function 'reqC' requires that 'Cucumber' conform to 'Copyable'}}
@@ -171,8 +169,6 @@ protocol Bird {
171169
}
172170

173171
protocol Eagle: Bird where Self.Song: ~Copyable {}// expected-error {{'Self.Song' required to be 'Copyable' but is marked with '~Copyable'}}
174-
// expected-error @-1{{cannot suppress '~Copyable' on generic parameter 'Self.Song' defined in outer scope}}
175-
176172

177173
protocol Pushable<Element> {
178174
associatedtype Element: ~Copyable

test/Generics/inverse_extensions.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ protocol HasAssoc {
1616
associatedtype A
1717
}
1818
extension HasAssoc where Self.A: ~Copyable {}
19-
// expected-error@-1 {{cannot suppress '~Copyable' on generic parameter 'Self.A' defined in outer scope}}
20-
// expected-error@-2 {{'Self.A' required to be 'Copyable' but is marked with '~Copyable'}}
19+
// expected-error@-1 {{'Self.A' required to be 'Copyable' but is marked with '~Copyable'}}
2120

2221
class Box<T: ~Copyable> {}
2322
extension Box where T: ~Copyable {}

0 commit comments

Comments
 (0)