Skip to content

Commit 6013431

Browse files
committed
SR-5740 Refactoring action to convert if statement to switch
1 parent 904bd0b commit 6013431

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2249,7 +2249,7 @@ isApplicable(ResolvedRangeInfo Info, DiagnosticEngine &Diag) {
22492249
class ConditionalChecker : public ASTWalker {
22502250
public:
22512251
bool ParamsUseSameVars = true;
2252-
bool ConditionUseOnlyAllowedFunctions = true;
2252+
bool ConditionUseOnlyAllowedFunctions = false;
22532253
StringRef ExpectName;
22542254

22552255
Expr *walkToExprPost(Expr *E) {
@@ -2336,6 +2336,8 @@ isApplicable(ResolvedRangeInfo Info, DiagnosticEngine &Diag) {
23362336
bool check(StmtConditionElement ConditionElement) {
23372337
if (ConditionElement.getKind() == StmtConditionElement::CK_Availability)
23382338
return false;
2339+
if (ConditionElement.getKind() == StmtConditionElement::CK_PatternBinding)
2340+
checker.ConditionUseOnlyAllowedFunctions = true;
23392341
ConditionElement.walk(checker);
23402342
return checker.allCheckPassed();
23412343
}

test/refactoring/ConvertToSwitchStmt/basic.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,43 +134,57 @@ func checkEmptyBody(e: E) {
134134
// RUN: rm -rf %t.result && mkdir -p %t.result
135135

136136
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=9:3 -end-pos=16:4 > %t.result/L9-3.swift
137+
// RUN: %target-swift-frontend-typecheck %t.result/L9-3.swift
137138
// RUN: diff -u %S/Outputs/basic/L9-3.swift.expected %t.result/L9-3.swift
138139

139140
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=20:3 -end-pos=25:4 > %t.result/L20-3.swift
141+
// RUN: %target-swift-frontend-typecheck %t.result/L20-3.swift
140142
// RUN: diff -u %S/Outputs/basic/L20-3.swift.expected %t.result/L20-3.swift
141143

142144
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=29:3 -end-pos=35:4 > %t.result/L29-3.swift
145+
// RUN: %target-swift-frontend-typecheck %t.result/L29-3.swift
143146
// RUN: diff -u %S/Outputs/basic/L29-3.swift.expected %t.result/L29-3.swift
144147

145148
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=39:3 -end-pos=45:4 > %t.result/L39-3.swift
149+
// RUN: %target-swift-frontend-typecheck %t.result/L39-3.swift
146150
// RUN: diff -u %S/Outputs/basic/L39-3.swift.expected %t.result/L39-3.swift
147151

148152
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=50:3 -end-pos=52:4 > %t.result/L50-3.swift
153+
// RUN: %target-swift-frontend-typecheck %t.result/L50-3.swift
149154
// RUN: diff -u %S/Outputs/basic/L50-3.swift.expected %t.result/L50-3.swift
150155

151156
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=54:3 -end-pos=56:4 > %t.result/L54-3.swift
157+
// RUN: %target-swift-frontend-typecheck %t.result/L54-3.swift
152158
// RUN: diff -u %S/Outputs/basic/L54-3.swift.expected %t.result/L54-3.swift
153159

154160
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=60:3 -end-pos=62:4 > %t.result/L60-3.swift
161+
// RUN: %target-swift-frontend-typecheck %t.result/L60-3.swift
155162
// RUN: diff -u %S/Outputs/basic/L60-3.swift.expected %t.result/L60-3.swift
156163

157164
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=64:3 -end-pos=67:4 > %t.result/L64-3.swift
165+
// RUN: %target-swift-frontend-typecheck %t.result/L64-3.swift
158166
// RUN: diff -u %S/Outputs/basic/L64-3.swift.expected %t.result/L64-3.swift
159167

160168
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=71:3 -end-pos=77:4 > %t.result/L71-3.swift
169+
// RUN: %target-swift-frontend-typecheck %t.result/L71-3.swift
161170
// RUN: diff -u %S/Outputs/basic/L71-3.swift.expected %t.result/L71-3.swift
162171

163172
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=82:3 -end-pos=90:4 > %t.result/L82-3.swift
173+
// RUN: %target-swift-frontend-typecheck %t.result/L82-3.swift
164174
// RUN: diff -u %S/Outputs/basic/L82-3.swift.expected %t.result/L82-3.swift
165175

166176
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=99:3 -end-pos=103:4 > %t.result/L99-3.swift
177+
// RUN: %target-swift-frontend-typecheck %t.result/L99-3.swift
167178
// RUN: diff -u %S/Outputs/basic/L99-3.swift.expected %t.result/L99-3.swift
168179

169180
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=108:3 -end-pos=116:4 > %t.result/L108-3.swift
181+
// RUN: %target-swift-frontend-typecheck %t.result/L108-3.swift
170182
// RUN: diff -u %S/Outputs/basic/L108-3.swift.expected %t.result/L108-3.swift
171183

172184
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=118:3 -end-pos=124:4 > %t.result/L118-3.swift
185+
// RUN: %target-swift-frontend-typecheck %t.result/L118-3.swift
173186
// RUN: diff -u %S/Outputs/basic/L118-3.swift.expected %t.result/L118-3.swift
174187

175188
// RUN: %refactor -convert-to-switch-stmt -source-filename %s -pos=128:3 -end-pos=131:4 > %t.result/L128-3.swift
189+
// RUN: %target-swift-frontend-typecheck %t.result/L128-3.swift
176190
// RUN: diff -u %S/Outputs/basic/L128-3.swift.expected %t.result/L128-3.swift

0 commit comments

Comments
 (0)