Skip to content

Commit c818172

Browse files
committed
Don't handle refutable patterns in async transform
These aren't currently supported.
1 parent 800a9c5 commit c818172

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

lib/IDE/Refactoring.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4988,6 +4988,11 @@ struct CallbackClassifier {
49884988
if (!Cond.isValid())
49894989
return None;
49904990

4991+
// If the condition involves a refutable pattern, we can't currently handle
4992+
// it.
4993+
if (Cond.BindPattern && Cond.BindPattern->isRefutablePattern())
4994+
return None;
4995+
49914996
// For certain types of condition, they need to appear in certain lists.
49924997
auto CondType = *Cond.Type;
49934998
switch (CondType) {
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: %empty-directory(%t)
2+
3+
enum E : Error { case e }
4+
5+
func anyCompletion(_ completion: (Any?, Error?) -> Void) {}
6+
7+
// RUN: %refactor -convert-call-to-async-alternative -dump-text -source-filename %s -pos=%(line+1):1 | %FileCheck -check-prefix=TEST-UNHANDLED %s
8+
anyCompletion { val, err in
9+
if let x = val {
10+
print("a")
11+
}
12+
if let _ = val {
13+
print("b")
14+
}
15+
if case let x? = val {
16+
print("c")
17+
}
18+
if case let _? = val {
19+
print("d")
20+
}
21+
if case E.e? = val {
22+
print("e")
23+
}
24+
if case (let x as String)? = val {
25+
print("f")
26+
}
27+
if case let "" as String = val {
28+
print("g")
29+
}
30+
}
31+
32+
// TEST-UNHANDLED: let x = try await anyCompletion()
33+
// TEST-UNHANDLED-NEXT: print("a")
34+
// TEST-UNHANDLED-NEXT: print("b")
35+
// TEST-UNHANDLED-NEXT: print("c")
36+
// TEST-UNHANDLED-NEXT: print("d")
37+
// TEST-UNHANDLED-NEXT: if case E.e? = <#x#> {
38+
// TEST-UNHANDLED-NEXT: print("e")
39+
// TEST-UNHANDLED-NEXT: }
40+
// TEST-UNHANDLED-NEXT: if case (let x as String)? = <#x#> {
41+
// TEST-UNHANDLED-NEXT: print("f")
42+
// TEST-UNHANDLED-NEXT: }
43+
// TEST-UNHANDLED-NEXT: if case let "" as String = <#x#> {
44+
// TEST-UNHANDLED-NEXT: print("g")
45+
// TEST-UNHANDLED-NEXT: }

0 commit comments

Comments
 (0)