File tree Expand file tree Collapse file tree 2 files changed +91
-0
lines changed Expand file tree Collapse file tree 2 files changed +91
-0
lines changed Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: %target-swift-frontend -c -update-code -swift-version 4 -primary-file %s -emit-migrated-file-path %t/optional_try_migration.result.swift -o %t/rename-func-decl.swift.remap
3
+ // RUN: diff -u %S/optional_try_migration.swift.expected %t/optional_try_migration.result.swift
4
+
5
+ func throwOrOptional( ) throws -> Int ? {
6
+ return 3
7
+ }
8
+
9
+ func throwOrInt( ) throws -> Int {
10
+ return 3
11
+ }
12
+
13
+ func doubleOptional( ) -> Int ? ? {
14
+ return 3
15
+ }
16
+
17
+ func testIfLet( ) {
18
+ if let optionalX = try ? throwOrOptional ( ) , // This comment should be preserved
19
+ let y = Optional ( 3 ) , // This will stay here
20
+ let x = optionalX // this comment will be moved
21
+ {
22
+ print ( x, y)
23
+ return
24
+ }
25
+
26
+ if let optionalX = doubleOptional ( ) ,
27
+ let x = optionalX
28
+ {
29
+ // This one shouldn't be changed
30
+ print ( x)
31
+ }
32
+
33
+ if let x = try ? throwOrInt ( ) ,
34
+ let y = try ? throwOrInt ( ) {
35
+ // This one shouldn't be changed
36
+ print ( x, y)
37
+ }
38
+
39
+ if let optionalX = try ? throwOrOptional ( ) ,
40
+ let optionalY = try ? throwOrOptional ( ) ,
41
+ let x = optionalX,
42
+ let y = optionalY
43
+ {
44
+ print ( x, y)
45
+ }
46
+ }
Original file line number Diff line number Diff line change
1
+ // RUN: %empty-directory(%t)
2
+ // RUN: %target-swift-frontend -c -update-code -swift-version 4 -primary-file %s -emit-migrated-file-path %t/optional_try_migration.result.swift -o %t/rename-func-decl.swift.remap
3
+ // RUN: diff -u %S/optional_try_migration.swift.expected %t/optional_try_migration.result.swift
4
+
5
+ func throwOrOptional() throws -> Int? {
6
+ return 3
7
+ }
8
+
9
+ func throwOrInt() throws -> Int {
10
+ return 3
11
+ }
12
+
13
+ func doubleOptional() -> Int?? {
14
+ return 3
15
+ }
16
+
17
+ func testIfLet() {
18
+ if let x = try? throwOrOptional(), // This comment should be preserved
19
+ let y = Optional(3) // this will stay here // this comment will be moved
20
+ {
21
+ print(x, y)
22
+ return
23
+ }
24
+
25
+ if let optionalX = doubleOptional(),
26
+ let x = optionalX
27
+ {
28
+ // This one shouldn't be changed
29
+ print(x)
30
+ }
31
+
32
+ if let x = try? throwOrInt(),
33
+ let y = try? throwOrInt() {
34
+ // This one shouldn't be changed
35
+ print(x, y)
36
+ }
37
+
38
+ if let optionalX = try? throwOrOptional(),
39
+ let optionalY = try? throwOrOptional(),
40
+ let x = optionalX,
41
+ let y = optionalY
42
+ {
43
+ print(x, y)
44
+ }
45
+ }
You can’t perform that action at this time.
0 commit comments