Skip to content

Commit 50b8348

Browse files
benlangmuirtkremenek
authored andcommitted
[FixCode] Don't accept fixit that inserts commas; they break placeholders (#2869)
These fixits interact poorly with code that has <#editor placeholder#>s in it, inserting commas inside the placeholder. rdar://problem/26623964
1 parent 379b0db commit 50b8348

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

lib/FrontendTool/FrontendTool.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,8 @@ class JSONFixitWriter : public DiagnosticConsumer {
555555
return true;
556556

557557
// Do not add a semi as it is wrong in most cases during migration
558-
if (Info.ID == diag::statement_same_line_without_semi.ID)
558+
if (Info.ID == diag::statement_same_line_without_semi.ID ||
559+
Info.ID == diag::expected_separator.ID)
559560
return false;
560561
// The following interact badly with the swift migrator, they are undoing
561562
// migration of arguments to preserve the no-label for first argument.

test/FixCode/fixits-apply.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,9 @@ var graph: Graph3
142142

143143
class GraphNoFix<NodeType : SomeProt> {}
144144
var graph: GraphNoFix
145+
146+
func evilCommas(s: String) {
147+
_ = s[s.startIndex..<<#editorplaceholder#>]
148+
_ = true ? s[s.startIndex..<<#editorplaceholder#>] : ""
149+
_ = [s.startIndex..<<#editorplaceholder#>]
150+
}

test/FixCode/fixits-apply.swift.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,3 +145,9 @@ var graph: Graph3<AnyObject>
145145

146146
class GraphNoFix<NodeType : SomeProt> {}
147147
var graph: GraphNoFix
148+
149+
func evilCommas(s: String) {
150+
_ = s[s.startIndex..<<#editorplaceholder#>]
151+
_ = true ? s[s.startIndex..<<#editorplaceholder#>] : ""
152+
_ = [s.startIndex..<<#editorplaceholder#>]
153+
}

0 commit comments

Comments
 (0)