diff --git a/lib/AST/ArgumentList.cpp b/lib/AST/ArgumentList.cpp index 0b2cdf875a34a..8ecdf77f1bf8b 100644 --- a/lib/AST/ArgumentList.cpp +++ b/lib/AST/ArgumentList.cpp @@ -220,28 +220,35 @@ Optional ArgumentList::findArgumentExpr(Expr *expr, Expr *ArgumentList::packIntoImplicitTupleOrParen( ASTContext &ctx, llvm::function_ref getType) const { assert(!hasAnyInOutArgs() && "Cannot construct bare tuple/paren with inout"); + + // Make sure to preserve the source location info here and below as it may be + // needed for e.g serialization of its textual representation. if (auto *unary = getUnlabeledUnaryExpr()) { - auto *paren = new (ctx) ParenExpr(SourceLoc(), unary, SourceLoc()); + auto *paren = new (ctx) ParenExpr(getLParenLoc(), unary, getRParenLoc()); if (auto ty = getType(unary)) paren->setType(ParenType::get(ctx, ty)); paren->setImplicit(); return paren; } - SmallVector argExprs; - SmallVector argLabels; - SmallVector tupleEltTypes; + SmallVector argExprs; + SmallVector argLabels; + SmallVector argLabelLocs; + SmallVector tupleEltTypes; for (auto arg : *this) { auto *argExpr = arg.getExpr(); argExprs.push_back(argExpr); argLabels.push_back(arg.getLabel()); + argLabelLocs.push_back(arg.getLabelLoc()); if (auto ty = getType(argExpr)) tupleEltTypes.emplace_back(ty, arg.getLabel()); } assert(tupleEltTypes.empty() || tupleEltTypes.size() == argExprs.size()); - auto *tuple = TupleExpr::createImplicit(ctx, argExprs, argLabels); + auto *tuple = + TupleExpr::create(ctx, getLParenLoc(), argExprs, argLabels, argLabelLocs, + getRParenLoc(), /*implicit*/ true); if (empty() || !tupleEltTypes.empty()) tuple->setType(TupleType::get(tupleEltTypes, ctx)); diff --git a/test/ModuleInterface/default-args.swift b/test/ModuleInterface/default-args.swift index a08ff97212aad..f09706bd1bfce 100644 --- a/test/ModuleInterface/default-args.swift +++ b/test/ModuleInterface/default-args.swift @@ -54,3 +54,7 @@ public func hasMagicDefaultArgs(_ f: String = #file, _ fu: String = #function, _ // CHECK: func hasSimpleDefaultArgs(_ x: Swift.Int = 0, b: Swift.Int = 1) public func hasSimpleDefaultArgs(_ x: Int = 0, b: Int = 1) { } + +// rdar://83202870 (SR-15181): Make sure we can extract the textual representation here. +// CHECK: func hasTupleConstructionDefaultArgs(_ x: Any = (), y: (Swift.String, Swift.Int) = ("", 0)) +public func hasTupleConstructionDefaultArgs(_ x: Any = Void(), y: (String, Int) = (String, Int)("", 0)) {}