Skip to content

Instantly share code, notes, and snippets.

@Leonidas-from-XIV
Last active December 4, 2015 14:13
Show Gist options
  • Save Leonidas-from-XIV/143777bb5510dfe0f394 to your computer and use it in GitHub Desktop.
Save Leonidas-from-XIV/143777bb5510dfe0f394 to your computer and use it in GitHub Desktop.
switch is not an expression? what?
enum Either<T, V> {
case Left(T)
case Right(V)
}
var lint: Either<Int, Any> = Either.Left(42)
var rstring: Either<Any, String> = Either.Right("at you")
switch rstring {
case .Right(let x): print("right", x)
case .Left: print("not right")
}
/*
* <stdin>:15:37: error: expected expression in list of expressions
* print("is this not an expression?", switch lint {
* ^
* <stdin>:15:37: error: expected ',' separator
* print("is this not an expression?", switch lint {
* ^
*/
print("is this not an expression?", switch lint {
case .Left: "left"
case .Right: "right"
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment