Skip to content

Instantly share code, notes, and snippets.

@johnynek
Last active August 29, 2015 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnynek/dd4351f158b13a1db130 to your computer and use it in GitHub Desktop.
Save johnynek/dd4351f158b13a1db130 to your computer and use it in GitHub Desktop.
Bug with dependent types in scala 2.10
trait Path {
type A
}
trait Reader { self =>
def read(p: Path): Option[p.A]
def orElse(that: Reader): Reader = ComposedReader(this, that)
}
case class ComposedReader(first: Reader, second: Reader) extends Reader {
// this works
def read(p: Path): Option[p.A] = first.read(p).orElse(second.read(p))
/* this gives the error below
def read(p: Path) = first.read(p).orElse(second.read(p))
*/
}
/**
* This gives me a confusing message in scala 2.10.4:
[tw-mbp-oscar deptype-bug]$ scalac test.scala
test.scala:9: error: type mismatch;
found : Option[p.A]
required: Option[p.A]
def read(p: Path) = self.read(p).orElse(that.read(p))
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment