Skip to content

Commit

Permalink
Merge pull request swiftlang#26544 from owenv/appendInterpolation_sou…
Browse files Browse the repository at this point in the history
…rce_locs

Assign a SourceLoc to implicit appendInterpolation calls for diagnostics
  • Loading branch information
beccadax authored Aug 19, 2019
2 parents 971fb0a + 686e4a6 commit a2b8826
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/Parse/ParseExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1855,11 +1855,11 @@ parseStringSegments(SmallVectorImpl<Lexer::StringSegment> &Segments,
TokReceiver->registerTokenKindChange(Tok.getLoc(),
tok::string_interpolation_anchor);

auto callee = new (Context) UnresolvedDotExpr(InterpolationVarRef,
/*dotloc=*/BackSlashLoc,
appendInterpolation,
/*nameloc=*/DeclNameLoc(),
/*Implicit=*/true);
auto callee = new (Context)
UnresolvedDotExpr(InterpolationVarRef,
/*dotloc=*/BackSlashLoc, appendInterpolation,
/*nameloc=*/DeclNameLoc(Segment.Loc),
/*Implicit=*/true);
auto S = parseExprCallSuffix(makeParserResult(callee), true);

// If we stopped parsing the expression before the expression segment is
Expand Down
24 changes: 24 additions & 0 deletions test/Sema/diag_deprecated_string_interpolation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// RUN: %target-swift-frontend -swift-version 5 -typecheck %s 2>&1 | %FileCheck %s

extension DefaultStringInterpolation {
@available(*, deprecated) func appendInterpolation(deprecated: Int) {}
}

// Make sure diagnostics emitted via string interpolations have a reasonable source location

_ = "\(deprecated: 42)"
// CHECK: [[@LINE-1]]:7: warning: 'appendInterpolation(deprecated:)' is deprecated

_ = "hello, world\(deprecated: 42)!!!"
// CHECK: [[@LINE-1]]:19: warning: 'appendInterpolation(deprecated:)' is deprecated

_ = "\(42)\(deprecated: 42)test\(deprecated: 42)"
// CHECK: [[@LINE-1]]:12: warning: 'appendInterpolation(deprecated:)' is deprecated
// CHECK: [[@LINE-2]]:33: warning: 'appendInterpolation(deprecated:)' is deprecated

_ = """
This is a multiline literal with a deprecated interpolation:
\(deprecated: 42)
"""
// CHECK: [[@LINE-2]]:2: warning: 'appendInterpolation(deprecated:)' is deprecated

0 comments on commit a2b8826

Please sign in to comment.