Skip to content

Instantly share code, notes, and snippets.

@jemc
Created February 13, 2017 19:57
Show Gist options
  • Save jemc/0dddeb44f635480ad50db7190a228a37 to your computer and use it in GitHub Desktop.
Save jemc/0dddeb44f635480ad50db7190a228a37 to your computer and use it in GitHub Desktop.
A pattern for dealing with unreachable conditions in Pony.
class Unreachable
new create(value: (Stringable | None) = None, loc: SourceLoc = __loc) =>
@printf[I32](
"ABORT: Unreachable condition at %s:%zu (in %s method)\n".cstring(),
loc.file().cstring(), loc.line(), loc.method().cstring())
if value isnt None then
@printf[I32]("%s\n".cstring(), value.string().cstring())
end
@exit[None](I32(1))
fun apply(): I32 =>
match x
| let x': Foo => handle_foo(x')
| let x': Bar => handle_bar(x')
| let x': Baz => handle_baz(x')
else Unreachable(x); 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment