Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:13
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 dacr/4b10cd395025dde86b350a6e90f28678 to your computer and use it in GitHub Desktop.
Save dacr/4b10cd395025dde86b350a6e90f28678 to your computer and use it in GitHub Desktop.
scala3 feature examples - literal types / published by https://github.com/dacr/code-examples-manager #4335490b-72fe-46b6-95cf-7a84023569f6/64080b1a4739ca4fdbe323d0537555a369abb32b
// summary : scala3 feature examples - literal types
// keywords : scala3, tutorial
// publish : gist
// authors : David Crosson
// license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2)
// id : 4335490b-72fe-46b6-95cf-7a84023569f6
// created-on : 2021-03-25T11:22:13+01:00
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
//> using scala "3.1.1"
val pi: 3.14157 = 3.14157
val _: 3.14157 = 3.14 // compile error !
val choice0: 1|2|3 = 1
val choice1: 1|2|3 = 4 // compile error !
val choice2: Option["A"|"B"] = None
val choice3: Option["A"|"B"] = Some("A")
val choice4: Option["A"|"B"] = Some("C") // compile error !
type Choice="A"|"B"|"C"
val myChoice:Choice = "A"
val myChoice:Choice = "D" // compile error !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment