@@ -764,13 +764,15 @@ class Instrumenter : InstrumenterBase {
764
764
std::tie (ArgPattern, ArgVariable) = maybeFixupPrintArgument (AE);
765
765
766
766
AE->setFn (LoggerRef);
767
- Added<ApplyExpr *> AddedApply (AE); // safe because we've fixed up the args
768
767
769
- if (!doTypeCheck (Context, TypeCheckDC, AddedApply)) {
768
+ Expr *E = AE;
769
+ if (!doTypeCheckExpr (Context, TypeCheckDC, E)) {
770
770
return nullptr ;
771
771
}
772
772
773
- return buildLoggerCallWithApply (AddedApply, AE->getSourceRange ());
773
+ Added<Expr *> AddedExpr (E); // safe because we've fixed up the args
774
+
775
+ return buildLoggerCallWithAddedExpr (AddedExpr, E->getSourceRange ());
774
776
}
775
777
776
778
Added<Stmt *> logPostPrint (SourceRange SR) {
@@ -890,25 +892,30 @@ class Instrumenter : InstrumenterBase {
890
892
ArgumentList::forImplicitUnlabeled (Context, ArgsWithSourceRange);
891
893
ApplyExpr *LoggerCall =
892
894
CallExpr::createImplicit (Context, LoggerRef, ArgList);
893
- Added<ApplyExpr *> AddedLogger (LoggerCall);
894
895
895
- if (!doTypeCheck (Context, TypeCheckDC, AddedLogger)) {
896
+ Expr *E = LoggerCall;
897
+ // Type-check the newly created logger call. Note that the type-checker is
898
+ // free to change the expression type, so type-checking is performed
899
+ // before wrapping in Added<>.
900
+ if (!doTypeCheckExpr (Context, TypeCheckDC, E)) {
896
901
return nullptr ;
897
902
}
898
903
899
- return buildLoggerCallWithApply (AddedLogger, SR);
904
+ Added<Expr *> AddedLogger (E);
905
+
906
+ return buildLoggerCallWithAddedExpr (AddedLogger, SR);
900
907
}
901
908
902
- // Assumes Apply has already been type-checked.
903
- Added<Stmt *> buildLoggerCallWithApply (Added<ApplyExpr *> Apply ,
904
- SourceRange SR) {
909
+ // Assumes expr has already been type-checked.
910
+ Added<Stmt *> buildLoggerCallWithAddedExpr (Added<Expr *> AddedExpr ,
911
+ SourceRange SR) {
905
912
std::pair<PatternBindingDecl *, VarDecl *> PV =
906
- buildPatternAndVariable (*Apply );
913
+ buildPatternAndVariable (*AddedExpr );
907
914
908
- DeclRefExpr *DRE =
909
- new (Context) DeclRefExpr (ConcreteDeclRef (PV.second ), DeclNameLoc (),
910
- true , // implicit
911
- AccessSemantics::Ordinary, Apply ->getType ());
915
+ DeclRefExpr *DRE = new (Context)
916
+ DeclRefExpr (ConcreteDeclRef (PV.second ), DeclNameLoc (),
917
+ true , // implicit
918
+ AccessSemantics::Ordinary, AddedExpr ->getType ());
912
919
913
920
UnresolvedDeclRefExpr *SendDataRef = new (Context)
914
921
UnresolvedDeclRefExpr (SendDataName, DeclRefKind::Ordinary,
@@ -919,9 +926,8 @@ class Instrumenter : InstrumenterBase {
919
926
auto *ArgList = ArgumentList::forImplicitUnlabeled (Context, {DRE});
920
927
Expr *SendDataCall =
921
928
CallExpr::createImplicit (Context, SendDataRef, ArgList);
922
- Added<Expr *> AddedSendData (SendDataCall);
923
929
924
- if (!doTypeCheck (Context, TypeCheckDC, AddedSendData )) {
930
+ if (!doTypeCheckExpr (Context, TypeCheckDC, SendDataCall )) {
925
931
return nullptr ;
926
932
}
927
933
0 commit comments