@@ -204,10 +204,16 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
204
204
paramRefExpr->setType (param->getType ());
205
205
206
206
auto specParamTy = specializedFuncDecl->getParameters ()->get (paramIndex)->getType ();
207
- auto cast = ForcedCheckedCastExpr::createImplicit (
208
- ctx, paramRefExpr, specParamTy);
209
207
210
- forwardingParams.push_back (Argument (SourceLoc (), Identifier (), cast));
208
+ Expr *argExpr = nullptr ;
209
+ if (specParamTy->isEqual (paramRefExpr->getType ())) {
210
+ argExpr = paramRefExpr;
211
+ } else {
212
+ argExpr = ForcedCheckedCastExpr::createImplicit (ctx, paramRefExpr,
213
+ specParamTy);
214
+ }
215
+
216
+ forwardingParams.push_back (Argument (SourceLoc (), Identifier (), argExpr));
211
217
paramIndex++;
212
218
}
213
219
@@ -220,10 +226,16 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
220
226
specializedFuncCallExpr->setType (specializedFuncDecl->getResultInterfaceType ());
221
227
specializedFuncCallExpr->setThrows (false );
222
228
223
- auto cast = ForcedCheckedCastExpr::createImplicit (
224
- ctx, specializedFuncCallExpr, thunkDecl->getResultInterfaceType ());
229
+ Expr *resultExpr = nullptr ;
230
+ if (specializedFuncCallExpr->getType ()->isEqual (thunkDecl->getResultInterfaceType ())) {
231
+ resultExpr = specializedFuncCallExpr;
232
+ } else {
233
+ resultExpr = ForcedCheckedCastExpr::createImplicit (
234
+ ctx, specializedFuncCallExpr, thunkDecl->getResultInterfaceType ());
235
+ }
225
236
226
- auto returnStmt = new (ctx) ReturnStmt (SourceLoc (), cast, /* implicit=*/ true );
237
+ auto returnStmt = new (ctx)
238
+ ReturnStmt (SourceLoc (), resultExpr, /* implicit=*/ true );
227
239
auto body = BraceStmt::create (ctx, SourceLoc (), {returnStmt}, SourceLoc (),
228
240
/* implicit=*/ true );
229
241
return {body, /* isTypeChecked=*/ true };
0 commit comments