Last active
April 25, 2023 05:39
-
-
Save niw/e8d3f2f31f18c4a008fc61b4b76b37e4 to your computer and use it in GitHub Desktop.
A problemtic code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// With Swift 5.8, it crashes on runtime due to reference count problem. | |
// With Swift 5.9-dev (LLVM d59f7189924eff9, Swift 12f2c2eb92c4c6a), today's nightly, it crashes due to an assertion. | |
class Box<T> { | |
private var value: T | |
init(_ value: T) { | |
self.value = value | |
} | |
func mutate(_ mutation: (inout T) -> Void) { | |
mutation(&self.value) | |
} | |
} | |
func f() { | |
let box: Box<() -> Void> = Box { | |
} | |
let s = "meow" | |
box.mutate { value in | |
value = { | |
s | |
} | |
} | |
} | |
f() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment