You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sema: Generalize the 'invariant Self requirement' check to handle a related case
There are three kinds of invariant 'Self' uses here:
- 'Self' appears as the left hand side of a same-type requirement between type parameters
- 'Self' appears as a structural component of the right hand side of a concrete type requirement
- 'Self' appears as a structural component of the right hand side of a superclass requirement
My previous fix only handled the first case. Generalize it to handle all three.
Fixes rdar://problem/74944514.
Copy file name to clipboardExpand all lines: test/Generics/non_final_class_conforms_same_type_requirement_on_self.swift
+30-1Lines changed: 30 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,7 @@ public protocol Q {
14
14
// exactly equal C; since C is not final, this means the conformance
15
15
// is not covariant.
16
16
publicclassC:P{
17
-
// expected-warning@-1 {{non-final class 'C' cannot safely conform to protocol 'P', which requires that 'Self' is exactly equal to 'Self.A.B'; this is an error in Swift 6}}
17
+
// expected-warning@-1 {{non-final class 'C' cannot safely conform to protocol 'P', which requires that 'Self.A.B' is exactly equal to 'Self'; this is an error in Swift 6}}
18
18
publictypealiasA=D
19
19
}
20
20
@@ -45,3 +45,32 @@ public func takesBoth1<T>(_: T) where T : P, T : C {}
45
45
46
46
// CHECK-LABEL: Generic signature: <U where U : C>
47
47
publicfunc takesBoth2<U>(_:U)where U :C, U :P{}
48
+
49
+
// 'Self' can also occur inside of a concrete type or superclass requirement.
50
+
publicclassG<T>{}
51
+
52
+
publicprotocolConcreteExampleP{
53
+
associatedtypeA:Qwhere A.B ==G<Self>
54
+
}
55
+
56
+
publicclassConcreteExampleC:ConcreteExampleP{
57
+
// expected-warning@-1 {{non-final class 'ConcreteExampleC' cannot safely conform to protocol 'ConcreteExampleP', which requires that 'Self.A.B' is exactly equal to 'G<Self>'; this is an error in Swift 6}}
58
+
publictypealiasA=ConcreteExampleD
59
+
}
60
+
61
+
publicclassConcreteExampleD:Q{
62
+
publictypealiasB=G<ConcreteExampleC>
63
+
}
64
+
65
+
publicprotocolSuperclassExampleP{
66
+
associatedtypeA:Qwhere A.B :G<Self>
67
+
}
68
+
69
+
publicclassSuperclassExampleC:SuperclassExampleP{
70
+
// expected-warning@-1 {{non-final class 'SuperclassExampleC' cannot safely conform to protocol 'SuperclassExampleP', which requires that 'Self.A.B' inherit from 'G<Self>'; this is an error in Swift 6}}
Copy file name to clipboardExpand all lines: test/Generics/rdar80503090.swift
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ extension P where T : Q {
20
20
}
21
21
22
22
classC:P{}
23
-
// expected-warning@-1 {{non-final class 'C' cannot safely conform to protocol 'P', which requires that 'Self' is exactly equal to 'Self.T'; this is an error in Swift 6}}
23
+
// expected-warning@-1 {{non-final class 'C' cannot safely conform to protocol 'P', which requires that 'Self.T' is exactly equal to 'Self'; this is an error in Swift 6}}
24
24
25
25
extensionPwhere T :C{
26
26
// CHECK-LABEL: Generic signature: <Self where Self : C>
Copy file name to clipboardExpand all lines: validation-test/compiler_crashers_2_fixed/0189-sr10033.swift
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -15,9 +15,9 @@ extension P2 {
15
15
}
16
16
17
17
classC1:P1{
18
-
// expected-warning@-1 {{non-final class 'C1' cannot safely conform to protocol 'P1', which requires that 'Self' is exactly equal to 'Self.A2.A1'; this is an error in Swift 6}}
18
+
// expected-warning@-1 {{non-final class 'C1' cannot safely conform to protocol 'P1', which requires that 'Self.A2.A1' is exactly equal to 'Self'; this is an error in Swift 6}}
19
19
classA2:P2{
20
-
// expected-warning@-1 {{non-final class 'C1.A2' cannot safely conform to protocol 'P2', which requires that 'Self' is exactly equal to 'Self.A1.A2'; this is an error in Swift 6}}
20
+
// expected-warning@-1 {{non-final class 'C1.A2' cannot safely conform to protocol 'P2', which requires that 'Self.A1.A2' is exactly equal to 'Self'; this is an error in Swift 6}}
0 commit comments