@@ -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,33 @@ 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)) {
901
+ return nullptr ;
902
+ }
903
+
904
+ Added<Expr *> AddedLogger (E);
905
+ if (*AddedLogger == nullptr ) {
896
906
return nullptr ;
897
907
}
898
908
899
- return buildLoggerCallWithApply (AddedLogger, SR);
909
+ return buildLoggerCallWithAddedExpr (AddedLogger, SR);
900
910
}
901
911
902
- // Assumes Apply has already been type-checked.
903
- Added<Stmt *> buildLoggerCallWithApply (Added<ApplyExpr *> Apply ,
904
- SourceRange SR) {
912
+ // Assumes expr has already been type-checked.
913
+ Added<Stmt *> buildLoggerCallWithAddedExpr (Added<Expr *> AddedExpr ,
914
+ SourceRange SR) {
905
915
std::pair<PatternBindingDecl *, VarDecl *> PV =
906
- buildPatternAndVariable (*Apply );
916
+ buildPatternAndVariable (*AddedExpr );
907
917
908
- DeclRefExpr *DRE =
909
- new (Context) DeclRefExpr (ConcreteDeclRef (PV.second ), DeclNameLoc (),
910
- true , // implicit
911
- AccessSemantics::Ordinary, Apply ->getType ());
918
+ DeclRefExpr *DRE = new (Context)
919
+ DeclRefExpr (ConcreteDeclRef (PV.second ), DeclNameLoc (),
920
+ true , // implicit
921
+ AccessSemantics::Ordinary, AddedExpr ->getType ());
912
922
913
923
UnresolvedDeclRefExpr *SendDataRef = new (Context)
914
924
UnresolvedDeclRefExpr (SendDataName, DeclRefKind::Ordinary,
@@ -919,9 +929,8 @@ class Instrumenter : InstrumenterBase {
919
929
auto *ArgList = ArgumentList::forImplicitUnlabeled (Context, {DRE});
920
930
Expr *SendDataCall =
921
931
CallExpr::createImplicit (Context, SendDataRef, ArgList);
922
- Added<Expr *> AddedSendData (SendDataCall);
923
932
924
- if (!doTypeCheck (Context, TypeCheckDC, AddedSendData )) {
933
+ if (!doTypeCheckExpr (Context, TypeCheckDC, SendDataCall )) {
925
934
return nullptr ;
926
935
}
927
936
0 commit comments