File tree Expand file tree Collapse file tree 2 files changed +33
-6
lines changed Expand file tree Collapse file tree 2 files changed +33
-6
lines changed Original file line number Diff line number Diff line change @@ -4047,20 +4047,23 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
4047
4047
if (simpleRepr->getIdentifier () != TC.Context .Id_Self )
4048
4048
return false ;
4049
4049
4050
+ // 'Self' in protocol extensions is not dynamic 'Self'.
4051
+ DeclContext *dc = func->getDeclContext ();
4052
+ for (auto parentDC = dc; !parentDC->isModuleScopeContext ();
4053
+ parentDC = parentDC->getParent ()) {
4054
+ if (parentDC->getAsProtocolExtensionContext ()) {
4055
+ return false ;
4056
+ }
4057
+ }
4058
+
4050
4059
// Dynamic 'Self' is only permitted on methods.
4051
- auto dc = func->getDeclContext ();
4052
4060
if (!dc->isTypeContext ()) {
4053
4061
TC.diagnose (simpleRepr->getIdLoc (), diag::dynamic_self_non_method,
4054
4062
dc->isLocalContext ());
4055
4063
simpleRepr->setInvalid ();
4056
4064
return true ;
4057
4065
}
4058
4066
4059
- // 'Self' in protocol extensions is not dynamic 'Self'.
4060
- if (dc->getAsProtocolExtensionContext ()) {
4061
- return false ;
4062
- }
4063
-
4064
4067
// 'Self' is only a dynamic self on class methods and
4065
4068
// protocol requirements.
4066
4069
auto declaredType = dc->getDeclaredTypeOfContext ();
Original file line number Diff line number Diff line change @@ -35,6 +35,30 @@ protocol P0 {
35
35
func g( _ ds: Self ) // okay
36
36
}
37
37
38
+ extension P0 {
39
+ func h( ) -> Self { // okay
40
+ func g( _ t : Self ) -> Self { // okay
41
+ return t
42
+ }
43
+ return g ( self )
44
+ }
45
+ }
46
+
47
+ protocol P1 : class {
48
+ func f( ) -> Self // okay
49
+
50
+ func g( _ ds: Self ) // okay
51
+ }
52
+
53
+ extension P1 {
54
+ func h( ) -> Self { // okay
55
+ func g( _ t : Self ) -> Self { // okay
56
+ return t
57
+ }
58
+ return g ( self )
59
+ }
60
+ }
61
+
38
62
// ----------------------------------------------------------------------------
39
63
// The 'self' type of a Self method is based on Self
40
64
class C1 {
You can’t perform that action at this time.
0 commit comments