Skip to content

Commit 1b74379

Browse files
committed
Add VariableType test cases for if/guard/while-let
- Add VariableType test case for guarded variables - Add if-let to VariableType test case - Add while-let test case for VariableType - Test pattern matching with VariableType - Test guard/while-case-let with VariableType
1 parent e547c06 commit 1b74379

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
if case let x? = Optional.some(5) {}
2+
if case let y: Int? = Optional.some(5) {}
3+
guard case let z: String? = Optional.some("a") else { fatalError() }
4+
while case let w: String? = Optional.some("b") {}
5+
6+
enum Pair<U, V> {
7+
case pair(U, V)
8+
}
9+
10+
switch Pair.pair(Optional.some(0), "test") {
11+
case .pair(let u, var v):
12+
break
13+
}
14+
15+
// RUN: %sourcekitd-test -req=collect-var-type %s -- %s | %FileCheck %s
16+
// CHECK: (1:13, 1:14): Int (explicit type: 0)
17+
// CHECK: (2:13, 2:14): Int? (explicit type: 1)
18+
// CHECK: (3:16, 3:17): String? (explicit type: 1)
19+
// CHECK: (4:16, 4:17): String? (explicit type: 1)
20+
// CHECK: (11:16, 11:17): Int? (explicit type: 0)
21+
// CHECK: (11:23, 11:24): String (explicit type: 0)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
guard var opt: Int = .some(23) else { fatalError() }
2+
3+
func foo() {
4+
guard let x = .some("abc") else { return }
5+
guard let y: String = .some("def") else { return }
6+
7+
if let z: Int = .some(4) {}
8+
9+
while var w: Int = .some(5) {}
10+
}
11+
12+
// RUN: %sourcekitd-test -req=collect-var-type %s -- %s | %FileCheck %s
13+
// CHECK: (1:11, 1:14): Int (explicit type: 1)
14+
// CHECK: (4:13, 4:14): String (explicit type: 0)
15+
// CHECK: (5:13, 5:14): String (explicit type: 1)
16+
// CHECK: (7:10, 7:11): Int (explicit type: 1)
17+
// CHECK: (9:13, 9:14): Int (explicit type: 1)

0 commit comments

Comments
 (0)