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

'type mismatch' error for pattern matcher code compiling fine in 2.9. #6951

Closed
scabug opened this issue Jan 9, 2013 · 3 comments
Closed
Assignees
Labels
Milestone

Comments

@scabug
Copy link

scabug commented Jan 9, 2013

The following code compiles fine on 2.9.3-RC1, but fails with a type mismatch error on 2.10.0.

package tree

abstract class Tree {

  type FinalBranch <: Branch

  trait Branch {
    this: FinalBranch =>
    def myself: FinalBranch = this
  }

}

object Matcher {
  def unapply[T <: Tree](branch: T#Branch) = Some(branch.myself)
}

object Helper {
  def itself[T <: Tree](branch: T#Branch) = branch.myself
  def optionItself[T <: Tree](branch: T#Branch) = Some(branch.myself)
}

object Oak extends Tree {
  type FinalBranch = Branch
  class Branch extends super.Branch {
    this: FinalBranch =>
  }
}

object Caller extends App {
  val oakBranch = new Oak.Branch
  println(oakBranch.getClass()) // <-- class tree.Oak$Branch
  val naked = Helper.itself(oakBranch)
  println(naked.getClass()) // <-- class tree.Oak$Branch
  val unwrapped = Helper.optionItself(oakBranch).get
  println(unwrapped.getClass()) // <-- class tree.Oak$Branch
  val matched = oakBranch match {
    case Matcher(branch) => branch // <-- type mismatch; found: T#Branch; required: Oak.Branch
  }
}

The error:

$ scalac tree/Tree.scala 
tree/Tree.scala:38: error: type mismatch;
 found   : T#Branch
 required: tree.Oak.Branch
    case Matcher(branch) => branch // <-- type mismatch; found: T#Branch; required: Oak.Branch
                ^
one error found

This error was first reported to Scala IDE in ticket #1001404.

@scabug
Copy link
Author

scabug commented Jan 9, 2013

Imported From: https://issues.scala-lang.org/browse/SI-6951?orig=1
Reporter: @skyluc
Affected Versions: 2.10.0

@scabug
Copy link
Author

scabug commented Jan 9, 2013

@scabug
Copy link
Author

scabug commented Jan 13, 2013

@retronym said:
scala/scala#1887

@scabug scabug closed this as completed Feb 5, 2013
@scabug scabug added the patmat label Apr 7, 2017
@scabug scabug added this to the 2.10.1 milestone Apr 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants