Skip to content

Commit cd8c64c

Browse files
committed
couple of sourceloc fixes
1 parent 4fa5bd2 commit cd8c64c

File tree

7 files changed

+36
-14
lines changed

7 files changed

+36
-14
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2519,9 +2519,7 @@ class PatternBindingDecl final : public Decl,
25192519
Pattern *Pat, Expr *E,
25202520
DeclContext *Parent);
25212521

2522-
SourceLoc getStartLoc() const {
2523-
return StaticLoc.isValid() ? StaticLoc : VarLoc;
2524-
}
2522+
SourceLoc getStartLoc() const;
25252523
SourceRange getSourceRange() const;
25262524

25272525
unsigned getNumPatternEntries() const {
@@ -8409,9 +8407,7 @@ class FuncDecl : public AbstractFunctionDecl {
84098407
SourceLoc getStaticLoc() const { return StaticLoc; }
84108408
SourceLoc getFuncLoc() const { return FuncLoc; }
84118409

8412-
SourceLoc getStartLoc() const {
8413-
return StaticLoc.isValid() ? StaticLoc : FuncLoc;
8414-
}
8410+
SourceLoc getStartLoc() const;
84158411
SourceRange getSourceRange() const;
84168412

84178413
TypeRepr *getResultTypeRepr() const { return FnRetType.getTypeRepr(); }

lib/AST/Decl.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2497,6 +2497,19 @@ StringRef PatternBindingEntry::getInitStringRepresentation(
24972497
return extractInlinableText(ctx, init, scratch);
24982498
}
24992499

2500+
SourceLoc PatternBindingDecl::getStartLoc() const {
2501+
if (StaticLoc.isValid())
2502+
return StaticLoc;
2503+
2504+
if (VarLoc.isValid())
2505+
return VarLoc;
2506+
2507+
if (getPatternList().empty())
2508+
return SourceLoc();
2509+
2510+
return getPatternList().front().getSourceRange().Start;
2511+
}
2512+
25002513
SourceRange PatternBindingDecl::getSourceRange() const {
25012514
SourceLoc startLoc = getStartLoc();
25022515
SourceLoc endLoc = getPatternList().empty()
@@ -11423,6 +11436,19 @@ DestructorDecl *DestructorDecl::getSuperDeinit() const {
1142311436
return nullptr;
1142411437
}
1142511438

11439+
SourceLoc FuncDecl::getStartLoc() const {
11440+
if (StaticLoc.isValid())
11441+
return StaticLoc;
11442+
11443+
if (FuncLoc.isValid())
11444+
return FuncLoc;
11445+
11446+
if (getNameLoc().isValid())
11447+
return getNameLoc();
11448+
11449+
return getOriginalBodySourceRange().Start;
11450+
}
11451+
1142611452
SourceRange FuncDecl::getSourceRange() const {
1142711453
SourceLoc startLoc = getStartLoc();
1142811454

lib/Parse/ParseExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3637,7 +3637,7 @@ Parser::parseExprCollectionElement(std::optional<bool> &isDictionary) {
36373637
} else {
36383638
diagnose(Tok, diag::expected_colon_in_dictionary_literal);
36393639
Value = makeParserResult(makeParserError(),
3640-
new (Context) ErrorExpr(SourceRange()));
3640+
new (Context) ErrorExpr(PreviousLoc));
36413641
}
36423642

36433643
// Make a tuple of Key Value pair.

test/Concurrency/async_main_resolution.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ extension MainProtocol {
6363
#endif
6464

6565
// CHECK-IS-SYNC-LABEL: "MyMain" interface_type="MyMain.Type"
66-
// CHECK-IS-SYNC: (func_decl {{.*}}implicit "$main()" interface_type="(MyMain.Type) -> () -> ()"
66+
// CHECK-IS-SYNC: (func_decl {{.*}}implicit range={{.*}} "$main()" interface_type="(MyMain.Type) -> () -> ()"
6767
// CHECK-IS-SYNC: (declref_expr implicit type="(MyMain.Type) -> () -> ()"
6868

6969
// CHECK-IS-ASYNC-LABEL: "MyMain" interface_type="MyMain.Type"
70-
// CHECK-IS-ASYNC: (func_decl {{.*}}implicit "$main()" interface_type="(MyMain.Type) -> () async -> ()"
70+
// CHECK-IS-ASYNC: (func_decl {{.*}}implicit range={{.*}} "$main()" interface_type="(MyMain.Type) -> () async -> ()"
7171
// CHECK-IS-ASYNC: (declref_expr implicit type="(MyMain.Type) -> () async -> ()"
7272

7373
// CHECK-IS-ERROR1: error: 'MyMain' is annotated with '@main' and must provide a main static function of type {{\(\) -> Void or \(\) throws -> Void|\(\) -> Void, \(\) throws -> Void, \(\) async -> Void, or \(\) async throws -> Void}}

test/Concurrency/where_clause_main_resolution.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ protocol App {
2525
// CHECK-SAME: interface_type="<Self where Self : App> (Self.Type) -> () async -> ()"
2626

2727
extension App where Configuration == Config1 {
28-
// CHECK-CONFIG1: (func_decl {{.*}}implicit "$main()" interface_type="(MainType.Type) -> () -> ()"
28+
// CHECK-CONFIG1: (func_decl {{.*}}implicit range=[{{.*}}:[[@LINE+20]]:1 - line:[[@LINE+20]]:1] "$main()" interface_type="(MainType.Type) -> () -> ()"
2929
// CHECK-CONFIG1: [[SOURCE_FILE]]:[[# @LINE+1 ]]
3030
static func main() { }
3131
}
3232

3333
extension App where Configuration == Config2 {
34-
// CHECK-CONFIG2: (func_decl {{.*}}implicit "$main()" interface_type="(MainType.Type) -> () async -> ()"
34+
// CHECK-CONFIG2: (func_decl {{.*}}implicit range=[{{.*}}:[[@LINE+14]]:1 - line:[[@LINE+14]]:1] "$main()" interface_type="(MainType.Type) -> () async -> ()"
3535
// CHECK-CONFIG2: [[SOURCE_FILE]]:[[# @LINE+1 ]]
3636
static func main() async { }
3737
}
3838

3939
extension App where Configuration == Config3 {
40-
// CHECK-CONFIG3-ASYNC: (func_decl {{.*}}implicit "$main()" interface_type="(MainType.Type) -> () async -> ()"
40+
// CHECK-CONFIG3-ASYNC: (func_decl {{.*}}implicit range=[{{.*}}:[[@LINE+8]]:1 - line:[[@LINE+8]]:1] "$main()" interface_type="(MainType.Type) -> () async -> ()"
4141
// CHECK-CONFIG3-ASYNC: [[SOURCE_FILE]]:[[DEFAULT_ASYNCHRONOUS_MAIN_LINE]]
4242
}
4343

test/attr/ApplicationMain/attr_main_throws.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct MyBase {
77
}
88
}
99

10-
// CHECK-AST: (func_decl {{.*}} implicit "$main()" interface_type="(MyBase.Type) -> () throws -> ()" access=internal static
10+
// CHECK-AST: (func_decl {{.*}} implicit range=[{{.*}}:[[@LINE-6]]:1 - line:[[@LINE-6]]:1] "$main()" interface_type="(MyBase.Type) -> () throws -> ()" access=internal static
1111
// CHECK-AST-NEXT: (parameter "self" {{.*}})
1212
// CHECK-AST-NEXT: (parameter_list)
1313
// CHECK-AST-NEXT: (brace_stmt implicit

test/expr/capture/top-level-guard.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ let closureCapture: () -> Void = { [x] in
3939
}
4040

4141
// CHECK-LABEL: (defer_stmt
42-
// CHECK-NEXT: (func_decl{{.*}}implicit "$defer()" interface_type="() -> ()" access=fileprivate captures=(x<direct><noescape>)
42+
// CHECK-NEXT: (func_decl{{.*}}implicit range={{.*}} "$defer()" interface_type="() -> ()" access=fileprivate captures=(x<direct><noescape>)
4343
defer {
4444
_ = x
4545
}

0 commit comments

Comments
 (0)