Skip to content
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

Duplicate pattern variable on generated variables #4030

Closed
Blaisorblade opened this issue Feb 21, 2018 · 1 comment
Closed

Duplicate pattern variable on generated variables #4030

Blaisorblade opened this issue Feb 21, 2018 · 1 comment

Comments

@Blaisorblade
Copy link
Contributor

Pattern matches have to be linear in type variables. But apparently Dotty demands the same in generated type variables as well, at least if they come from a single type variable.

Sample code:

sealed trait Root[T]
case object C1 extends Root[Int]
case object C2 extends Root[String]
//case class C3[X, Y]() extends Root[X|Y|(X => X)]
case class C3[X, Y]() extends Root[(X => X)|(Y => Y)|(X => Y)]
case class C4[X, Y]() extends Root[(X => X)|(Y => Y)|(X => Y)]

object TestGADT {
  //type Foo // abstract

  def f[A <: Seq[_], B, Foo >: A => B](v: Root[Foo], u: Root[Foo]) = (v, u) match {
    //case C1 =>
    //case C2 =>
    case (C3(), C3()) =>
  }
  //f(C3[Int, Int]())
  //implicitly[Int <:< Int|(Int => Int)]
  //implicitly[(Int => Int) <:< String|(Int => Int)]//($conforms[Int => Int])
  //f[Int, Int, Int|(Int => Int)](C3[Int, Int]())
  //f(C3[Int, Int]())
  f(C3[Seq[_], Long](), C4[Seq[_], Long]())
}

Error (with -explain, on commit 4149833):

-- [E005] Naming Error: /Users/pgiarrusso/git/dotty/tests/IterableTest.scala:157:12
157 |    case (C3(), C3()) =>
    |            ^
    |            duplicate pattern variable: `_$6`

Explanation
===========
For each case bound variable names have to be unique. In:

case (C3(), C3()) =>

`_$6` is not unique. Rename one of the bound variables!

one error found
@Blaisorblade
Copy link
Contributor Author

Assigned to @liufengyun, please reassign if my guess was bad.

liufengyun added a commit to dotty-staging/dotty that referenced this issue Feb 22, 2018
liufengyun added a commit to dotty-staging/dotty that referenced this issue Feb 26, 2018
liufengyun added a commit to dotty-staging/dotty that referenced this issue Feb 26, 2018
liufengyun added a commit that referenced this issue Feb 27, 2018
Fix #4030: avoid adding duplicate binders
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

2 participants