Skip to content

[5.3][AST] Restore getSourceRange() on DefaultArgumentExpr #31873

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions include/swift/AST/Expr.h
Original file line number Diff line number Diff line change
Expand Up @@ -4133,9 +4133,7 @@ class DefaultArgumentExpr final : public Expr {
DefaultArgsOwner(defaultArgsOwner), ParamIndex(paramIndex), Loc(loc),
ContextOrCallerSideExpr(dc) { }

SourceRange getSourceRange() const { return {}; }

SourceLoc getArgumentListLoc() const { return Loc; }
SourceRange getSourceRange() const { return Loc; }

ConcreteDeclRef getDefaultArgsOwner() const {
return DefaultArgsOwner;
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/Expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1244,6 +1244,10 @@ SourceRange TupleExpr::getSourceRange() const {
} else {
// Scan backwards for a valid source loc.
for (Expr *expr : llvm::reverse(getElements())) {
// Default arguments are located at the start of their parent tuple, so
// skip over them.
if (isa<DefaultArgumentExpr>(expr))
continue;
end = expr->getEndLoc();
if (end.isValid()) {
break;
Expand Down
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ Expr *CallerSideDefaultArgExprRequest::evaluate(

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

Expand Down
9 changes: 9 additions & 0 deletions test/DebugInfo/callexpr.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %target-swift-frontend %s -g -emit-ir -o - | %FileCheck %s
// RUN: %target-swift-frontend %s -g -emit-ir -o - | %FileCheck --check-prefix=CHECK2 %s

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

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

struct MyType {}
func bar(x: MyType = MyType()) {}

// CHECK2: call {{.*}}MyType{{.*}}, !dbg ![[DEFAULTARG:.*]]
// CHECK2: call {{.*}}bar{{.*}}, !dbg ![[BARCALL:.*]]
bar() // CHECK2: ![[DEFAULTARG]] = !DILocation(line: [[@LINE]], column: 4
// CHECK2: ![[BARCALL]] = !DILocation(line: [[@LINE-1]], column: 1