Skip to content

Commit 07b6bf4

Browse files
committed
AST: Removed extraneous space from let/var as a parameter fixit.
1 parent 904ba9b commit 07b6bf4

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

lib/AST/DiagnosticEngine.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,12 @@ InFlightDiagnostic &InFlightDiagnostic::fixItRemove(SourceRange R) {
173173
// If we're removing something (e.g. a keyword), do a bit of extra work to
174174
// make sure that we leave the code in a good place, without extraneous white
175175
// space around its hole. Specifically, check to see there is whitespace
176-
// before and after the end of range. If so, nuke the space afterward to keep
177-
// things consistent.
176+
// or a paren before and whitespace after the end of range. If so, nuke
177+
// the space afterward to keep things consistent.
178+
char charBefore = extractCharBefore(SM, charRange.getStart());
179+
178180
if (extractCharAfter(SM, charRange.getEnd()) == ' ' &&
179-
isspace(extractCharBefore(SM, charRange.getStart()))) {
181+
(isspace(charBefore) || charBefore == '(')) {
180182
charRange = CharSourceRange(charRange.getStart(),
181183
charRange.getByteLength()+1);
182184
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: not %swift -emit-sil -target %target-triple %s -emit-fixits-path %t.remap -diagnostics-editor-mode
2+
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
3+
4+
func foo(var arg: Int) {}
5+
func bar(let arg: Int) {}
6+
7+
func baz(var arg: Int, var arg2: Int) {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: not %swift -emit-sil -target %target-triple %s -emit-fixits-path %t.remap -diagnostics-editor-mode
2+
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
3+
4+
func foo(arg: Int) {}
5+
func bar(arg: Int) {}
6+
7+
func baz(arg: Int, arg2: Int) {}

0 commit comments

Comments
 (0)