Skip to content

Commit a2b8826

Browse files
authored
Merge pull request #26544 from owenv/appendInterpolation_source_locs
Assign a SourceLoc to implicit appendInterpolation calls for diagnostics
2 parents 971fb0a + 686e4a6 commit a2b8826

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

lib/Parse/ParseExpr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1855,11 +1855,11 @@ parseStringSegments(SmallVectorImpl<Lexer::StringSegment> &Segments,
18551855
TokReceiver->registerTokenKindChange(Tok.getLoc(),
18561856
tok::string_interpolation_anchor);
18571857

1858-
auto callee = new (Context) UnresolvedDotExpr(InterpolationVarRef,
1859-
/*dotloc=*/BackSlashLoc,
1860-
appendInterpolation,
1861-
/*nameloc=*/DeclNameLoc(),
1862-
/*Implicit=*/true);
1858+
auto callee = new (Context)
1859+
UnresolvedDotExpr(InterpolationVarRef,
1860+
/*dotloc=*/BackSlashLoc, appendInterpolation,
1861+
/*nameloc=*/DeclNameLoc(Segment.Loc),
1862+
/*Implicit=*/true);
18631863
auto S = parseExprCallSuffix(makeParserResult(callee), true);
18641864

18651865
// If we stopped parsing the expression before the expression segment is
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// RUN: %target-swift-frontend -swift-version 5 -typecheck %s 2>&1 | %FileCheck %s
2+
3+
extension DefaultStringInterpolation {
4+
@available(*, deprecated) func appendInterpolation(deprecated: Int) {}
5+
}
6+
7+
// Make sure diagnostics emitted via string interpolations have a reasonable source location
8+
9+
_ = "\(deprecated: 42)"
10+
// CHECK: [[@LINE-1]]:7: warning: 'appendInterpolation(deprecated:)' is deprecated
11+
12+
_ = "hello, world\(deprecated: 42)!!!"
13+
// CHECK: [[@LINE-1]]:19: warning: 'appendInterpolation(deprecated:)' is deprecated
14+
15+
_ = "\(42)\(deprecated: 42)test\(deprecated: 42)"
16+
// CHECK: [[@LINE-1]]:12: warning: 'appendInterpolation(deprecated:)' is deprecated
17+
// CHECK: [[@LINE-2]]:33: warning: 'appendInterpolation(deprecated:)' is deprecated
18+
19+
_ = """
20+
This is a multiline literal with a deprecated interpolation:
21+
22+
\(deprecated: 42)
23+
"""
24+
// CHECK: [[@LINE-2]]:2: warning: 'appendInterpolation(deprecated:)' is deprecated

0 commit comments

Comments
 (0)