@@ -220,28 +220,35 @@ Optional<unsigned> ArgumentList::findArgumentExpr(Expr *expr,
220220Expr *ArgumentList::packIntoImplicitTupleOrParen (
221221 ASTContext &ctx, llvm::function_ref<Type(Expr *)> getType) const {
222222 assert (!hasAnyInOutArgs () && " Cannot construct bare tuple/paren with inout" );
223+
224+ // Make sure to preserve the source location info here and below as it may be
225+ // needed for e.g serialization of its textual representation.
223226 if (auto *unary = getUnlabeledUnaryExpr ()) {
224- auto *paren = new (ctx) ParenExpr (SourceLoc (), unary, SourceLoc ());
227+ auto *paren = new (ctx) ParenExpr (getLParenLoc (), unary, getRParenLoc ());
225228 if (auto ty = getType (unary))
226229 paren->setType (ParenType::get (ctx, ty));
227230 paren->setImplicit ();
228231 return paren;
229232 }
230233
231- SmallVector<Expr *, 8 > argExprs;
232- SmallVector<Identifier, 8 > argLabels;
233- SmallVector<TupleTypeElt, 8 > tupleEltTypes;
234+ SmallVector<Expr *, 2 > argExprs;
235+ SmallVector<Identifier, 2 > argLabels;
236+ SmallVector<SourceLoc, 2 > argLabelLocs;
237+ SmallVector<TupleTypeElt, 2 > tupleEltTypes;
234238
235239 for (auto arg : *this ) {
236240 auto *argExpr = arg.getExpr ();
237241 argExprs.push_back (argExpr);
238242 argLabels.push_back (arg.getLabel ());
243+ argLabelLocs.push_back (arg.getLabelLoc ());
239244 if (auto ty = getType (argExpr))
240245 tupleEltTypes.emplace_back (ty, arg.getLabel ());
241246 }
242247 assert (tupleEltTypes.empty () || tupleEltTypes.size () == argExprs.size ());
243248
244- auto *tuple = TupleExpr::createImplicit (ctx, argExprs, argLabels);
249+ auto *tuple =
250+ TupleExpr::create (ctx, getLParenLoc (), argExprs, argLabels, argLabelLocs,
251+ getRParenLoc (), /* implicit*/ true );
245252 if (empty () || !tupleEltTypes.empty ())
246253 tuple->setType (TupleType::get (tupleEltTypes, ctx));
247254
0 commit comments