Skip to content

Commit 82ee98c

Browse files
authored
Merge pull request #4229 from akyrtzi/misplaced-paren-fixit-swift3
[AST] Fix issue with fixits wrapping over an interpolated string
2 parents cf8dcde + b88a061 commit 82ee98c

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

include/swift/AST/Expr.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ class StringLiteralExpr : public LiteralExpr {
989989
/// "[\(min)..\(max)]"
990990
/// \endcode
991991
class InterpolatedStringLiteralExpr : public LiteralExpr {
992+
/// Points at the beginning quote.
992993
SourceLoc Loc;
993994
MutableArrayRef<Expr *> Segments;
994995
Expr *SemanticExpr;
@@ -1007,10 +1008,12 @@ class InterpolatedStringLiteralExpr : public LiteralExpr {
10071008
void setSemanticExpr(Expr *SE) { SemanticExpr = SE; }
10081009

10091010
SourceLoc getStartLoc() const {
1010-
return Segments.front()->getStartLoc();
1011+
return Loc;
10111012
}
10121013
SourceLoc getEndLoc() const {
1013-
return Segments.back()->getEndLoc();
1014+
// SourceLocs are token based, and the interpolated string is one string
1015+
// token, so the range should be (Start == End).
1016+
return Loc;
10141017
}
10151018

10161019
static bool classof(const Expr *E) {

test/FixCode/fixits-apply.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ func testMask13(a: MyEventMask2?) {
7878
testMask1(a: a) // no fix, nullability mismatch.
7979
}
8080

81+
struct SomeName : RawRepresentable {
82+
init(_ rawValue: String) {}
83+
init(rawValue: String) {}
84+
var rawValue: String { return "" }
85+
}
86+
func testPassSomeName(_: SomeName) {}
87+
func testConvertSomeName(s: String) {
88+
testPassSomeName("\(s)}")
89+
}
90+
8191
enum MyEnumType : UInt32 {
8292
case invalid
8393
}

test/FixCode/fixits-apply.swift.result

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ func testMask13(a: MyEventMask2?) {
7878
testMask1(a: a) // no fix, nullability mismatch.
7979
}
8080

81+
struct SomeName : RawRepresentable {
82+
init(_ rawValue: String) {}
83+
init(rawValue: String) {}
84+
var rawValue: String { return "" }
85+
}
86+
func testPassSomeName(_: SomeName) {}
87+
func testConvertSomeName(s: String) {
88+
testPassSomeName(SomeName(rawValue: "\(s)}"))
89+
}
90+
8191
enum MyEnumType : UInt32 {
8292
case invalid
8393
}

0 commit comments

Comments
 (0)