Skip to content

Commit ca09e1d

Browse files
authored
Merge pull request #3054 from kubamracek/section-closures
SE-0492: Update proposal to allow trivial closures
2 parents 966b1cc + f09f664 commit ca09e1d

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

proposals/0492-section-control.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,12 @@ This proposal defines a **constant expression** as being one of:
194194
- a floating-point literal of type Float or Double
195195
- a boolean literal of type Bool
196196
- a direct reference to a non-generic function using its name (the function itself is not generic, and also it must not be defined in a generic context)
197+
- a closure literal with no captures and not in a generic context
197198
- a direct reference to a non-generic metatype using the type name directly (the type itself is not generic, and also it must not be defined in a generic context), where the type is non-resilient
198199
- a tuple composed of only other constant expressions
199200
- an array literal of type InlineArray composed of only other constant expressions
200201

201-
Explicitly, this definition currently does **not allow** any operators, using any user-defined named types, any other standard type (e.g. strings, dictionaries, sets), using closures, or referencing any variables by name. See below for examples of valid and invalid constant expressions:
202+
Explicitly, this definition currently does **not allow** any operators, using any user-defined named types, any other standard type (e.g. strings, dictionaries, sets), using closures with captures, or referencing any variables by name. See below for examples of valid and invalid constant expressions:
202203

203204
```swift
204205
@section("...") let a = 42 //
@@ -222,7 +223,15 @@ func foo() -> Int { return 42 }
222223
@section("...") let func4 = Bool.self.random // ❌ not a direct reference
223224
@section("...") let func5 = (Bool.self as Bool.Type).random // ❌ not a direct reference
224225
@section("...") let func6 = [Int].randomElement // ❌ generic
225-
@section("...") let func7 = { } // ❌ not using name
226+
@section("...") let func7 = { } //
227+
@section("...") let func8 = { (x: Int) in print(x) } //
228+
struct Generic<T> {
229+
@section("...") static let func9 = { print("1") } // ❌ generic context
230+
}
231+
struct NonGeneric {
232+
static var member: Int = 42
233+
@section("...") static let func10 = { print(member) } // ❌ capture
234+
}
226235

227236
struct S { }
228237
@section("...") let metatype1 = S.self //

0 commit comments

Comments
 (0)