@@ -204,10 +204,16 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
204204 paramRefExpr->setType (param->getType ());
205205
206206 auto specParamTy = specializedFuncDecl->getParameters ()->get (paramIndex)->getType ();
207- auto cast = ForcedCheckedCastExpr::createImplicit (
208- ctx, paramRefExpr, specParamTy);
209207
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));
211217 paramIndex++;
212218 }
213219
@@ -220,10 +226,16 @@ synthesizeDependentTypeThunkParamForwarding(AbstractFunctionDecl *afd, void *con
220226 specializedFuncCallExpr->setType (specializedFuncDecl->getResultInterfaceType ());
221227 specializedFuncCallExpr->setThrows (false );
222228
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+ }
225236
226- auto returnStmt = new (ctx) ReturnStmt (SourceLoc (), cast, /* implicit=*/ true );
237+ auto returnStmt = new (ctx)
238+ ReturnStmt (SourceLoc (), resultExpr, /* implicit=*/ true );
227239 auto body = BraceStmt::create (ctx, SourceLoc (), {returnStmt}, SourceLoc (),
228240 /* implicit=*/ true );
229241 return {body, /* isTypeChecked=*/ true };
0 commit comments