Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Allow variables in pattern alternatives using union types #175

Closed
Lasering opened this issue Feb 15, 2021 · 1 comment
Closed

Allow variables in pattern alternatives using union types #175

Lasering opened this issue Feb 15, 2021 · 1 comment

Comments

@Lasering
Copy link

Lasering commented Feb 15, 2021

For the following ADT hierarchy:

sealed trait Foo
case object Empty extends Foo
case class JustList(list: List[Int]) extends Foo
case class PathAndList(path: String, list: List[Int]) extends Foo

The following code could compile:

val a: Foo = new JustList(List(1, 2, 3))
a match {
 case JustList(list) | PathAndList(_, list) => println(list)
 case Empty => println("Empty")
}

Where the variable list would type check to List[Int] | List[Int] which could be further reduced to List[Int].
Currently the compiler issues the error Illegal variable list in pattern alternative.

The remaining scenarios could be type checked as follows:

  • case JustList(list) | PathAndList(list, _) => would typecheck to List[Int] | String
  • case JustList(list) | PathAndList(_, _) => would typecheck to List[Int] | Null
@smarter
Copy link
Member

smarter commented Feb 15, 2021

Duplicate of #12

@smarter smarter marked this as a duplicate of #12 Feb 15, 2021
@smarter smarter closed this as completed Feb 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants