Skip to content

Instantly share code, notes, and snippets.

@niw
Last active April 25, 2023 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niw/e8d3f2f31f18c4a008fc61b4b76b37e4 to your computer and use it in GitHub Desktop.
Save niw/e8d3f2f31f18c4a008fc61b4b76b37e4 to your computer and use it in GitHub Desktop.
A problemtic code
// 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