File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -1063,8 +1063,10 @@ static Type diagnoseUnknownType(TypeResolution resolution,
1063
1063
AbstractFunctionDecl *methodDecl = dc->getInnermostMethodContext ();
1064
1064
bool declaringMethod = methodDecl &&
1065
1065
methodDecl->getDeclContext () == dc->getParentForLookup ();
1066
+ bool isPropertyOfClass = insideClass &&
1067
+ options.is (TypeResolverContext::PatternBindingDecl);
1066
1068
1067
- if (((!insideClass || !declaringMethod) &&
1069
+ if (((!insideClass || !declaringMethod) && !isPropertyOfClass &&
1068
1070
!options.is (TypeResolverContext::GenericRequirement)) ||
1069
1071
options.is (TypeResolverContext::ExplicitCastExpr)) {
1070
1072
Type SelfType = nominal->getSelfInterfaceType ();
Original file line number Diff line number Diff line change @@ -70,6 +70,15 @@ class A<T> {
70
70
// expected-warning@-1 {{conditional cast from 'Self' to 'Self' always succeeds}}
71
71
// expected-warning@-2 {{conditional downcast from 'Self?' to 'A<T>' is equivalent to an implicit conversion to an optional 'A<T>'}}
72
72
}
73
+ func copy( ) -> Self {
74
+ let copy = Self . init ( a: 11 )
75
+ return copy
76
+ }
77
+
78
+ var copied : Self { // expected-error {{'Self' is only available in a protocol or as the result of a method in a class; did you mean 'A'?}}
79
+ let copy = Self . init ( a: 11 )
80
+ return copy
81
+ }
73
82
}
74
83
75
84
class B : A < Int > {
@@ -88,6 +97,14 @@ class B: A<Int> {
88
97
override class func y( ) {
89
98
print ( " override \( Self . self) . \( #function) " )
90
99
}
100
+ override func copy( ) -> Self {
101
+ let copy = super. copy ( ) as! Self // supported
102
+ return copy
103
+ }
104
+ override var copied : Self { // expected-error {{'Self' is only available in a protocol or as the result of a method in a class; did you mean 'B'?}}
105
+ let copy = super. copied as! Self // unsupported
106
+ return copy
107
+ }
91
108
}
92
109
93
110
class C {
@@ -121,6 +138,15 @@ struct S2 {
121
138
// expected-warning@-1 {{conditional cast from 'S2.S3<T>' to 'S2.S3<T>' always succeeds}}
122
139
}
123
140
}
141
+ func copy( ) -> Self {
142
+ let copy = Self . init ( )
143
+ return copy
144
+ }
145
+
146
+ var copied : Self {
147
+ let copy = Self . init ( )
148
+ return copy
149
+ }
124
150
}
125
151
126
152
extension S2 {
You can’t perform that action at this time.
0 commit comments