|
| 1 | +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureRet | %FileCheck %s -check-prefix=TestSingleExprClosureRet |
| 2 | +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureRetVoid | %FileCheck %s -check-prefix=TestSingleExprClosureRetVoid |
| 3 | +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureRetUnresolved | %FileCheck %s -check-prefix=TestSingleExprClosureRetUnresolved |
| 4 | +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosure | %FileCheck %s -check-prefix=TestSingleExprClosure |
| 5 | +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureVoid | %FileCheck %s -check-prefix=TestSingleExprClosureRetVoid |
| 6 | +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureUnresolved | %FileCheck %s -check-prefix=TestSingleExprClosureRetUnresolved |
| 7 | +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureCall | %FileCheck %s -check-prefix=TestSingleExprClosure |
| 8 | +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestSingleExprClosureGlobal | %FileCheck %s -check-prefix=TestSingleExprClosureGlobal |
| 9 | +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestNonSingleExprClosureGlobal | %FileCheck %s -check-prefix=TestNonSingleExprClosureGlobal |
| 10 | +// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=TestNonSingleExprClosureUnresolved | %FileCheck %s -check-prefix=TestNonSingleExprClosureUnresolved |
| 11 | + |
| 12 | +struct TestSingleExprClosureRet { |
| 13 | + func void() -> Void {} |
| 14 | + func str() -> String { return "" } |
| 15 | + func int() -> Int { return 0 } |
| 16 | + |
| 17 | + func test() -> Int { |
| 18 | + return { () in |
| 19 | + return self.#^TestSingleExprClosureRet^# |
| 20 | + }() |
| 21 | + } |
| 22 | + |
| 23 | +// TestSingleExprClosureRet: Begin completions |
| 24 | +// TestSingleExprClosureRet-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; |
| 25 | +// TestSingleExprClosureRet-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Identical]: int()[#Int#]; |
| 26 | +// TestSingleExprClosureRet-DAG: Decl[InstanceMethod]/CurrNominal/NotRecommended/TypeRelation[Invalid]: void()[#Void#]; |
| 27 | +// TestSingleExprClosureRet: End completions |
| 28 | +} |
| 29 | + |
| 30 | +struct TestSingleExprClosureRetVoid { |
| 31 | + func void() -> Void {} |
| 32 | + func str() -> String { return "" } |
| 33 | + func int() -> Int { return 0 } |
| 34 | + |
| 35 | + func test() { |
| 36 | + return { () in |
| 37 | + return self.#^TestSingleExprClosureRetVoid^# |
| 38 | + }() |
| 39 | + } |
| 40 | + |
| 41 | +// TestSingleExprClosureRetVoid: Begin completions |
| 42 | +// TestSingleExprClosureRetVoid-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; |
| 43 | +// TestSingleExprClosureRetVoid-DAG: Decl[InstanceMethod]/CurrNominal: int()[#Int#]; |
| 44 | +// TestSingleExprClosureRetVoid-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Identical]: void()[#Void#]; |
| 45 | +// TestSingleExprClosureRetVoid: End completions |
| 46 | +} |
| 47 | + |
| 48 | +struct TestSingleExprClosureRetUnresolved { |
| 49 | + enum MyEnum { case myEnum } |
| 50 | + enum NotMine { case notMine } |
| 51 | + func mine() -> MyEnum { return .myEnum } |
| 52 | + func notMine() -> NotMine { return .notMine } |
| 53 | + |
| 54 | + func test() -> MyEnum { |
| 55 | + return { () in |
| 56 | + return .#^TestSingleExprClosureRetUnresolved^# |
| 57 | + }() |
| 58 | + } |
| 59 | + |
| 60 | +// TestSingleExprClosureRetUnresolved: Begin completions |
| 61 | +// TestSingleExprClosureRetUnresolved-NOT: notMine |
| 62 | +// TestSingleExprClosureRetUnresolved: Decl[EnumElement]/ExprSpecific: myEnum[#TestSingleExprClosure{{(Ret)?}}Unresolved.MyEnum#]; |
| 63 | +// TestSingleExprClosureRetUnresolved-NOT: notMine |
| 64 | +// TestSingleExprClosureRetUnresolved: End completions |
| 65 | +} |
| 66 | + |
| 67 | +struct TestSingleExprClosure { |
| 68 | + func void() -> Void {} |
| 69 | + func str() -> String { return "" } |
| 70 | + func int() -> Int { return 0 } |
| 71 | + |
| 72 | + func test() -> Int { |
| 73 | + return { () in |
| 74 | + self.#^TestSingleExprClosure^# |
| 75 | + }() |
| 76 | + } |
| 77 | +// TestSingleExprClosure: Begin completions |
| 78 | +// TestSingleExprClosure-DAG: Decl[InstanceMethod]/CurrNominal: str()[#String#]; |
| 79 | +// TestSingleExprClosure-DAG: Decl[InstanceMethod]/CurrNominal/TypeRelation[Identical]: int()[#Int#]; |
| 80 | +// NOTE: this differs from the one using a return keyword. |
| 81 | +// TestSingleExprClosure-DAG: Decl[InstanceMethod]/CurrNominal: void()[#Void#]; |
| 82 | +// TestSingleExprClosure: End completions |
| 83 | +} |
| 84 | + |
| 85 | +struct TestSingleExprClosureVoid { |
| 86 | + func void() -> Void {} |
| 87 | + func str() -> String { return "" } |
| 88 | + func int() -> Int { return 0 } |
| 89 | + |
| 90 | + func test() { |
| 91 | + return { () in |
| 92 | + self.#^TestSingleExprClosureVoid^# |
| 93 | + }() |
| 94 | + } |
| 95 | +} |
| 96 | + |
| 97 | +struct TestSingleExprClosureUnresolved { |
| 98 | + enum MyEnum { case myEnum } |
| 99 | + enum NotMine { case notMine } |
| 100 | + func mine() -> MyEnum { return .myEnum } |
| 101 | + func notMine() -> NotMine { return .notMine } |
| 102 | + |
| 103 | + func test() -> MyEnum { |
| 104 | + return { () in |
| 105 | + .#^TestSingleExprClosureUnresolved^# |
| 106 | + }() |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +struct TestSingleExprClosureCall { |
| 111 | + func void() -> Void {} |
| 112 | + func str() -> String { return "" } |
| 113 | + func int() -> Int { return 0 } |
| 114 | + |
| 115 | + func take(_: () -> Int) {} |
| 116 | + |
| 117 | + func test() { |
| 118 | + take { |
| 119 | + self.#^TestSingleExprClosureCall^# |
| 120 | + } |
| 121 | + } |
| 122 | +} |
| 123 | + |
| 124 | +struct TestSingleExprClosureGlobal { |
| 125 | + func void() -> Void {} |
| 126 | + func str() -> String { return "" } |
| 127 | + func int() -> Int { return 0 } |
| 128 | + |
| 129 | + func test() -> Int { |
| 130 | + return { () in |
| 131 | + #^TestSingleExprClosureGlobal^# |
| 132 | + }() |
| 133 | + } |
| 134 | +// TestSingleExprClosureGlobal: Begin completions |
| 135 | +// TestSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal: str()[#String#]; |
| 136 | +// TestSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal/TypeRelation[Identical]: int()[#Int#]; |
| 137 | +// TestSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal: void()[#Void#]; |
| 138 | +// TestSingleExprClosureGlobal: End completions |
| 139 | +} |
| 140 | + |
| 141 | +struct TestNonSingleExprClosureGlobal { |
| 142 | + func void() -> Void {} |
| 143 | + func str() -> String { return "" } |
| 144 | + func int() -> Int { return 0 } |
| 145 | + |
| 146 | + func test() -> Int { |
| 147 | + return { () in |
| 148 | + #^TestNonSingleExprClosureGlobal^# |
| 149 | + return 42 |
| 150 | + }() |
| 151 | + } |
| 152 | +// TestNonSingleExprClosureGlobal: Begin completions |
| 153 | +// TestNonSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal: str()[#String#]; |
| 154 | +// TestNonSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal: int()[#Int#]; |
| 155 | +// TestNonSingleExprClosureGlobal-DAG: Decl[InstanceMethod]/OutNominal: void()[#Void#]; |
| 156 | +// TestNonSingleExprClosureGlobal: End completions |
| 157 | +} |
| 158 | + |
| 159 | +struct TestNonSingleExprClosureUnresolved { |
| 160 | + enum MyEnum { case myEnum } |
| 161 | + enum NotMine { case notMine } |
| 162 | + func mine() -> MyEnum { return .myEnum } |
| 163 | + func notMine() -> NotMine { return .notMine } |
| 164 | + |
| 165 | + func test() -> Int { |
| 166 | + return { () in |
| 167 | + .#^TestNonSingleExprClosureUnresolved^# |
| 168 | + return 42 |
| 169 | + }() |
| 170 | + } |
| 171 | +// TestNonSingleExprClosureUnresolved-NOT: myEnum |
| 172 | +// TestNonSingleExprClosureUnresolved-NOT: notMine |
| 173 | +} |
0 commit comments