Skip to content

Update union-types.md #2180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2021
Merged

Update union-types.md #2180

merged 1 commit into from
Oct 18, 2021

Conversation

danecek
Copy link
Contributor

@danecek danecek commented Sep 14, 2021

// script.scala
type Hash=Int
case class UserName(name: String)
case class Password(hash: Hash)
val password = Password(123)
val name = UserName("Eve")
if true then name else password
val either: Password | UserName = if true then name else password

scala> :load script.scala
// defined alias type Hash = Int
// defined case class UserName
// defined case class Password
val password: Password = Password(123)
val name: UserName = UserName(Eve)
val res0: Object = UserName(Eve)
val either: Password | UserName = UserName(Eve)

// script.scala
type Hash=Int
case class UserName(name: String)
case class Password(hash: Hash)
val password = Password(123)
val name = UserName("Eve")
if true then name else password
val either: Password | UserName = if true then name else password

scala> :load script.scala
// defined alias type Hash = Int
// defined case class UserName
// defined case class Password
val password: Password = Password(123)
val name: UserName = UserName(Eve)
val res0: Object = UserName(Eve)
val either: Password | UserName = UserName(Eve)
Copy link
Contributor

@julienrf julienrf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @danecek

@julienrf julienrf merged commit 4f0a349 into scala:main Oct 18, 2021
@danecek danecek deleted the patch-2 branch October 22, 2021 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants