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
Copy file name to clipboardExpand all lines: test/Parse/self_rebinding.swift
+58Lines changed: 58 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -58,3 +58,61 @@ class MyCls {
58
58
something() // this should still refer `MyCls.something`.
59
59
}
60
60
}
61
+
62
+
// MARK: fix method called 'self' can be confused with regular 'self' https://bugs.swift.org/browse/SR-4559
63
+
64
+
func funcThatReturnsSomething(_ any:Any)->Any{
65
+
any
66
+
}
67
+
68
+
structTypeWithSelfMethod{
69
+
70
+
letproperty=self // expected-warning {{'self' refers to the method 'TypeWithSelfMethod.self', which may be unexpected}} expected-note{{use 'TypeWithSelfMethod.self' to silence this warning}} {{20-20=TypeWithSelfMethod.}}
71
+
72
+
// Existing warning expected, not confusable
73
+
letproperty2=self() // expected-error {{cannot use instance member 'self' within property initializer; property initializers run before 'self' is available}}
74
+
75
+
letpropertyFromClosure:()={
76
+
print(self) // expected-warning {{'self' refers to the method 'TypeWithSelfMethod.self', which may be unexpected}} expected-note{{use 'TypeWithSelfMethod.self' to silence this warning}} {{15-15=TypeWithSelfMethod.}}
77
+
}()
78
+
79
+
letpropertyFromFunc=funcThatReturnsSomething(self) // expected-warning {{'self' refers to the method 'TypeWithSelfMethod.self', which may be unexpected}} expected-note{{use 'TypeWithSelfMethod.self' to silence this warning}} {{53-53=TypeWithSelfMethod.}}
80
+
81
+
letpropertyFromFunc2=funcThatReturnsSomething(TypeWithSelfMethod.self) // OK
82
+
83
+
func `self`(){
84
+
85
+
}
86
+
}
87
+
88
+
/// Test fix_unqualified_access_member_named_self doesn't appear for computed var called `self`
89
+
/// it can't currently be referenced as a static member -- unlike a method with the same name
90
+
structTypeWithSelfComputedVar{
91
+
92
+
letproperty=self // expected-error {{cannot use instance member 'self' within property initializer; property initializers run before 'self' is available}}
93
+
94
+
letpropertyFromClosure:()={
95
+
print(self) // expected-error {{cannot use instance member 'self' within property initializer; property initializers run before 'self' is available}}
96
+
}()
97
+
98
+
letpropertyFromFunc=funcThatReturnsSomething(self) // expected-error {{cannot use instance member 'self' within property initializer; property initializers run before 'self' is available}}
99
+
100
+
var`self`:(){
101
+
()
102
+
}
103
+
}
104
+
105
+
/// Test fix_unqualified_access_member_named_self doesn't appear appear for property called `self`
106
+
/// it can't currently be referenced as a static member -- unlike a method with the same name
107
+
structTypeWithSelfProperty{
108
+
109
+
letproperty=self // expected-error {{cannot use instance member 'self' within property initializer; property initializers run before 'self' is available}}
110
+
111
+
letpropertyFromClosure:()={
112
+
print(self) // expected-error {{cannot use instance member 'self' within property initializer; property initializers run before 'self' is available}}
113
+
}()
114
+
115
+
letpropertyFromFunc=funcThatReturnsSomething(self) // expected-error {{cannot use instance member 'self' within property initializer; property initializers run before 'self' is available}}
0 commit comments