Skip to content

enum branches can extend any class #6601

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

Closed
Blaisorblade opened this issue Jun 4, 2019 · 2 comments
Closed

enum branches can extend any class #6601

Blaisorblade opened this issue Jun 4, 2019 · 2 comments

Comments

@Blaisorblade
Copy link
Contributor

Blaisorblade commented Jun 4, 2019

Noticed by accident that enum cases might extend the wrong enum. That is, Z below is accepted and should probably be rejected. I also confirmed that Z indeed extends Expr and not Var.

object GADTs2 {
  enum Var[G, A] {
    case Z[A, G] extends Expr[(A, G), A]
  }
  enum Expr[G, A] {
    case Lit[G](n: Int) extends Expr[G, Int]
        // case S[A, G](x:
  }
}
@smarter smarter changed the title enum branches might enum branches might extend the wrong enum Jun 5, 2019
@bishabosha
Copy link
Member

Actually you can extend anything at all

@bishabosha bishabosha changed the title enum branches might extend the wrong enum enum branches can extend any class Nov 5, 2019
@bishabosha
Copy link
Member

class Foo

enum Var[G, A] with
  case Z[A, G]() extends Foo

val isVar = Var.Z().isInstanceOf[Var[?,?]] // false
val isEnum = Var.Z().isInstanceOf[scala.Enum] // false

@bishabosha bishabosha mentioned this issue Nov 5, 2019
22 tasks
odersky added a commit to dotty-staging/dotty that referenced this issue Mar 5, 2020
odersky added a commit to dotty-staging/dotty that referenced this issue Mar 5, 2020
odersky added a commit to dotty-staging/dotty that referenced this issue Mar 5, 2020
bishabosha added a commit that referenced this issue Mar 5, 2020
Fix #6601: Check that an enum case extends its enum class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants