@@ -48,7 +48,8 @@ ValueDecl::getRuntimeDiscoverableAttributeGenerator(CustomAttr *attr) const {
48
48
return std::make_pair (body, init->getType ()->mapTypeOutOfContext ());
49
49
}
50
50
51
- static TypeRepr *buildTypeRepr (DeclContext *typeContext) {
51
+ static TypeRepr *buildTypeRepr (DeclContext *typeContext,
52
+ bool forMetatype = false ) {
52
53
assert (typeContext->isTypeContext ());
53
54
54
55
SmallVector<ComponentIdentTypeRepr *, 2 > components;
@@ -77,10 +78,17 @@ static TypeRepr *buildTypeRepr(DeclContext *typeContext) {
77
78
// Reverse the components to form a valid outer-to-inner name sequence.
78
79
std::reverse (components.begin (), components.end ());
79
80
80
- if (components.size () == 1 )
81
- return components.front ();
81
+ TypeRepr *typeRepr = nullptr ;
82
+ if (components.size () == 1 ) {
83
+ typeRepr = components.front ();
84
+ } else {
85
+ typeRepr = CompoundIdentTypeRepr::create (ctx, components);
86
+ }
82
87
83
- return CompoundIdentTypeRepr::create (ctx, components);
88
+ if (forMetatype)
89
+ return new (ctx) MetatypeTypeRepr (typeRepr, /* MetaLoc=*/ SourceLoc ());
90
+
91
+ return typeRepr;
84
92
}
85
93
86
94
// / Synthesizes a closure thunk that forwards all of the arguments
@@ -98,22 +106,22 @@ static ClosureExpr *synthesizeMethodThunk(DeclContext *thunkDC,
98
106
99
107
SmallVector<ParamDecl *, 4 > closureParams;
100
108
101
- NullablePtr<ParamDecl> selfParam;
102
- if (!method->isStatic ()) {
103
- auto *self = ParamDecl::createImplicit (
104
- ctx,
105
- /* argumentName=*/ Identifier (),
106
- /* parameterName=*/ ctx.Id_self ,
107
- /* type=*/ nominal->getDeclaredInterfaceType (), thunkDC,
108
- method->isMutating () ? ParamSpecifier::InOut : ParamSpecifier::Default);
109
-
109
+ ParamDecl *selfParam = ParamDecl::createImplicit (
110
+ ctx,
111
+ /* argumentName=*/ Identifier (),
112
+ /* parameterName=*/ ctx.Id_self ,
113
+ /* type=*/
114
+ method->isStatic () ? nominal->getInterfaceType ()
115
+ : nominal->getDeclaredInterfaceType (),
116
+ thunkDC,
117
+ method->isMutating () ? ParamSpecifier::InOut : ParamSpecifier::Default);
118
+ {
110
119
// This is very important for the solver, without a type repr
111
120
// it would create a type variable and attempt infer the type
112
121
// from the body.
113
- self ->setTypeRepr (buildTypeRepr (nominal));
122
+ selfParam ->setTypeRepr (buildTypeRepr (nominal, method-> isStatic () ));
114
123
115
- closureParams.push_back (self);
116
- selfParam = self;
124
+ closureParams.push_back (selfParam);
117
125
}
118
126
119
127
if (funcParams) {
@@ -139,14 +147,9 @@ static ClosureExpr *synthesizeMethodThunk(DeclContext *thunkDC,
139
147
// return self.<func>(<arguments>)
140
148
SmallVector<ASTNode, 2 > body;
141
149
{
142
- NullablePtr<Expr> baseExpr;
143
- if (method->isStatic ()) {
144
- baseExpr =
145
- TypeExpr::createImplicit (nominal->getDeclaredInterfaceType (), ctx);
146
- } else {
147
- baseExpr = new (ctx) DeclRefExpr ({selfParam.get ()}, /* Loc=*/ DeclNameLoc (),
148
- /* implicit=*/ true );
149
- }
150
+ NullablePtr<Expr> baseExpr =
151
+ new (ctx) DeclRefExpr ({selfParam}, /* Loc=*/ DeclNameLoc (),
152
+ /* implicit=*/ true );
150
153
151
154
auto *memberRef = new (ctx) MemberRefExpr (
152
155
baseExpr.get (), /* dotLoc=*/ SourceLoc (), {method}, /* loc=*/ DeclNameLoc (),
@@ -157,10 +160,9 @@ static ClosureExpr *synthesizeMethodThunk(DeclContext *thunkDC,
157
160
for (unsigned i = 0 , n = funcParams->size (); i != n; ++i) {
158
161
const auto *param = funcParams->get (i);
159
162
160
- Expr *argExpr = new (ctx)
161
- DeclRefExpr ({closureParams[method->isStatic () ? i : i + 1 ]},
162
- /* Loc=*/ DeclNameLoc (),
163
- /* implicit=*/ true );
163
+ Expr *argExpr = new (ctx) DeclRefExpr ({closureParams[i + 1 ]},
164
+ /* Loc=*/ DeclNameLoc (),
165
+ /* implicit=*/ true );
164
166
165
167
if (param->isInOut ()) {
166
168
argExpr = new (ctx) InOutExpr (/* operLoc=*/ SourceLoc (), argExpr,
0 commit comments