Skip to content

Instantly share code, notes, and snippets.

@eed3si9n
Forked from xuwei-k/Main.scala
Last active September 9, 2021 16:30
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 eed3si9n/69599b2994c284c40632b316f6251dec to your computer and use it in GitHub Desktop.
Save eed3si9n/69599b2994c284c40632b316f6251dec to your computer and use it in GitHub Desktop.
object Main {
def head[A](list: List[A]): A = list.head
def x1: List[Int] | List[String] = List(3)
// this conversion is ok. the opposite doesn't work.
def x2: List[Int | String] = x1
def x3 = head(x1)
def x4 = head(x2)
x3 : (Int | String) // compilation error with Matchable
x4 : (Int | String) // this succeeds
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment