Skip to content

Commit 43a607c

Browse files
authored
Merge pull request #31873 from nathawes/default-arg-location-sourceloc-5.3
[5.3][AST] Restore getSourceRange() on DefaultArgumentExpr
2 parents 4eac5a1 + 12693d5 commit 43a607c

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

include/swift/AST/Expr.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4214,9 +4214,7 @@ class DefaultArgumentExpr final : public Expr {
42144214
DefaultArgsOwner(defaultArgsOwner), ParamIndex(paramIndex), Loc(loc),
42154215
ContextOrCallerSideExpr(dc) { }
42164216

4217-
SourceRange getSourceRange() const { return {}; }
4218-
4219-
SourceLoc getArgumentListLoc() const { return Loc; }
4217+
SourceRange getSourceRange() const { return Loc; }
42204218

42214219
ConcreteDeclRef getDefaultArgsOwner() const {
42224220
return DefaultArgsOwner;

lib/AST/Expr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,10 @@ SourceRange TupleExpr::getSourceRange() const {
12721272
} else {
12731273
// Scan backwards for a valid source loc.
12741274
for (Expr *expr : llvm::reverse(getElements())) {
1275+
// Default arguments are located at the start of their parent tuple, so
1276+
// skip over them.
1277+
if (isa<DefaultArgumentExpr>(expr))
1278+
continue;
12751279
end = expr->getEndLoc();
12761280
if (end.isValid()) {
12771281
break;

lib/Sema/TypeCheckExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ Expr *CallerSideDefaultArgExprRequest::evaluate(
789789

790790
// Re-create the default argument using the location info of the call site.
791791
auto *initExpr =
792-
synthesizeCallerSideDefault(param, defaultExpr->getArgumentListLoc());
792+
synthesizeCallerSideDefault(param, defaultExpr->getLoc());
793793
auto *dc = defaultExpr->ContextOrCallerSideExpr.get<DeclContext *>();
794794
assert(dc && "Expected a DeclContext before type-checking caller-side arg");
795795

test/DebugInfo/callexpr.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// RUN: %target-swift-frontend %s -g -emit-ir -o - | %FileCheck %s
2+
// RUN: %target-swift-frontend %s -g -emit-ir -o - | %FileCheck --check-prefix=CHECK2 %s
23

34
func markUsed<T>(_ t: T) {}
45

@@ -15,3 +16,11 @@ let r = foo(
1516
) // CHECK: ![[OUTER]] = !DILocation(line: [[@LINE-3]],
1617
markUsed(r)
1718

19+
struct MyType {}
20+
func bar(x: MyType = MyType()) {}
21+
22+
// CHECK2: call {{.*}}MyType{{.*}}, !dbg ![[DEFAULTARG:.*]]
23+
// CHECK2: call {{.*}}bar{{.*}}, !dbg ![[BARCALL:.*]]
24+
bar() // CHECK2: ![[DEFAULTARG]] = !DILocation(line: [[@LINE]], column: 4
25+
// CHECK2: ![[BARCALL]] = !DILocation(line: [[@LINE-1]], column: 1
26+

0 commit comments

Comments
 (0)