|
| 1 | +func simple(bar: Int?) { |
| 2 | + if let bar { |
| 3 | + print(bar) |
| 4 | + } |
| 5 | +} |
| 6 | + |
| 7 | +// RUN: %sourcekitd-test -req=cursor -pos=1:13 %s -- %s | %FileCheck %s --check-prefix=SIMPLE_PARAM |
| 8 | +// SIMPLE_PARAM: source.lang.swift.decl.var.parameter (1:13-1:16) |
| 9 | +// SIMPLE_PARAM: Int |
| 10 | +// SIMPLE_PARAM: SECONDARY SYMBOLS BEGIN |
| 11 | +// There should be no secondary symbols |
| 12 | +// SIMPLE_PARAM-NEXT: SECONDARY SYMBOLS END |
| 13 | + |
| 14 | +// RUN: %sourcekitd-test -req=cursor -pos=2:10 %s -- %s | %FileCheck %s --check-prefix=SIMPLE_CAPTURE |
| 15 | +// SIMPLE_CAPTURE: source.lang.swift.decl.var.local (2:10-2:13) |
| 16 | +// SIMPLE_CAPTURE: Int |
| 17 | +// SIMPLE_CAPTURE: SECONDARY SYMBOLS BEGIN |
| 18 | +// SIMPLE_CAPTURE: source.lang.swift.ref.var.local (1:13-1:16) |
| 19 | +// SIMPLE_CAPTURE: Int? |
| 20 | + |
| 21 | +// RUN: %sourcekitd-test -req=cursor -pos=3:11 %s -- %s | %FileCheck %s --check-prefix=SIMPLE_REF |
| 22 | +// SIMPLE_REF: source.lang.swift.ref.var.local (2:10-2:13) |
| 23 | +// SIMPLE_REF: Int |
| 24 | +// SIMPLE_REF: SECONDARY SYMBOLS BEGIN |
| 25 | +// SIMPLE_REF: source.lang.swift.ref.var.local (1:13-1:16) |
| 26 | +// SIMPLE_REF: Int? |
| 27 | + |
| 28 | +func doubleNested(bar: Int??) { |
| 29 | + if let bar { |
| 30 | + if let bar { |
| 31 | + print(bar) |
| 32 | + } |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +// RUN: %sourcekitd-test -req=cursor -pos=29:10 %s -- %s | %FileCheck %s --check-prefix=DOUBLE_NESTED_FIRST_CAPTURE |
| 37 | +// DOUBLE_NESTED_FIRST_CAPTURE: source.lang.swift.decl.var.local (29:10-29:13) |
| 38 | +// DOUBLE_NESTED_FIRST_CAPTURE: Int? |
| 39 | +// DOUBLE_NESTED_FIRST_CAPTURE: SECONDARY SYMBOLS BEGIN |
| 40 | +// DOUBLE_NESTED_FIRST_CAPTURE: source.lang.swift.ref.var.local (28:19-28:22) |
| 41 | +// DOUBLE_NESTED_FIRST_CAPTURE: Int?? |
| 42 | + |
| 43 | +// RUN: %sourcekitd-test -req=cursor -pos=30:12 %s -- %s | %FileCheck %s --check-prefix=DOUBLE_NESTED_SECOND_CAPTURE |
| 44 | +// DOUBLE_NESTED_SECOND_CAPTURE: source.lang.swift.decl.var.local (30:12-30:15) |
| 45 | +// DOUBLE_NESTED_SECOND_CAPTURE: Int |
| 46 | +// DOUBLE_NESTED_SECOND_CAPTURE: SECONDARY SYMBOLS BEGIN |
| 47 | +// DOUBLE_NESTED_SECOND_CAPTURE: source.lang.swift.ref.var.local (29:10-29:13) |
| 48 | +// DOUBLE_NESTED_SECOND_CAPTURE: Int? |
| 49 | +// DOUBLE_NESTED_SECOND_CAPTURE: source.lang.swift.ref.var.local (28:19-28:22) |
| 50 | +// DOUBLE_NESTED_SECOND_CAPTURE: Int?? |
| 51 | + |
| 52 | +// RUN: %sourcekitd-test -req=cursor -pos=31:13 %s -- %s | %FileCheck %s --check-prefix=DOUBLE_NESTED_REF |
| 53 | +// DOUBLE_NESTED_REF: source.lang.swift.ref.var.local (30:12-30:15) |
| 54 | +// DOUBLE_NESTED_REF: Int |
| 55 | +// DOUBLE_NESTED_REF: SECONDARY SYMBOLS BEGIN |
| 56 | +// DOUBLE_NESTED_REF: source.lang.swift.ref.var.local (29:10-29:13) |
| 57 | +// DOUBLE_NESTED_REF: Int? |
| 58 | +// DOUBLE_NESTED_REF: source.lang.swift.ref.var.local (28:19-28:22) |
| 59 | +// DOUBLE_NESTED_REF: Int?? |
| 60 | + |
| 61 | +// Make sure we don't report secondary symbols if the variable is captured explicitly using '=' |
| 62 | +func explicitCapture(bar: Int?) { |
| 63 | + if let bar = bar { |
| 64 | + print(bar) |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +// RUN: %sourcekitd-test -req=cursor -pos=64:11 %s -- %s | %FileCheck %s --check-prefix=EXPLICIT_CAPTURE_REF |
| 69 | +// EXPLICIT_CAPTURE_REF: source.lang.swift.ref.var.local (63:10-63:13) |
| 70 | +// EXPLICIT_CAPTURE_REF: Int |
| 71 | +// EXPLICIT_CAPTURE_REF: SECONDARY SYMBOLS BEGIN |
| 72 | +// There should be no secondary symbols |
| 73 | +// EXPLICIT_CAPTURE_REF-NEXT: SECONDARY SYMBOLS END |
| 74 | + |
| 75 | +func multipleShorthand(bar: Int?, baz: Int?) { |
| 76 | + if let bar, let baz { |
| 77 | + print(bar) |
| 78 | + print(baz) |
| 79 | + } |
| 80 | +} |
| 81 | + |
| 82 | +// RUN: %sourcekitd-test -req=cursor -pos=77:11 %s -- %s | %FileCheck %s --check-prefix=MULTIPLE_SHORTHAND_BAR |
| 83 | +// MULTIPLE_SHORTHAND_BAR: source.lang.swift.ref.var.local (76:10-76:13) |
| 84 | +// MULTIPLE_SHORTHAND_BAR: Int |
| 85 | +// MULTIPLE_SHORTHAND_BAR: SECONDARY SYMBOLS BEGIN |
| 86 | +// MULTIPLE_SHORTHAND_BAR.lang.swift.ref.var.local (75:23-75:26) |
| 87 | +// MULTIPLE_SHORTHAND_BAR: Int? |
| 88 | + |
| 89 | +// RUN: %sourcekitd-test -req=cursor -pos=78:11 %s -- %s | %FileCheck %s --check-prefix=MULTIPLE_SHORTHAND_BAZ |
| 90 | +// MULTIPLE_SHORTHAND_BAZ: source.lang.swift.ref.var.local (76:19-76:22) |
| 91 | +// MULTIPLE_SHORTHAND_BAZ: Int |
| 92 | +// MULTIPLE_SHORTHAND_BAZ: SECONDARY SYMBOLS BEGIN |
| 93 | +// MULTIPLE_SHORTHAND_BAZ.lang.swift.ref.var.local (63:33-63:36) |
| 94 | +// MULTIPLE_SHORTHAND_BAZ: Int? |
| 95 | + |
| 96 | +func guardLet(bar: Int?) { |
| 97 | + guard let bar else { |
| 98 | + return |
| 99 | + } |
| 100 | + print(bar) |
| 101 | +} |
| 102 | + |
| 103 | +// RUN: %sourcekitd-test -req=cursor -pos=100:9 %s -- %s | %FileCheck %s --check-prefix=GUARD_LET |
| 104 | +// GUARD_LET: source.lang.swift.ref.var.local (97:13-97:16) |
| 105 | +// GUARD_LET: Int |
| 106 | +// GUARD_LET: SECONDARY SYMBOLS BEGIN |
| 107 | +// GUARD_LET.lang.swift.ref.var.local (96:15-96:18) |
| 108 | +// GUARD_LET: Int? |
0 commit comments