Created
June 17, 2012 03:22
-
-
Save jorgeortiz85/2943283 to your computer and use it in GitHub Desktop.
dependent method types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait CompanionProvider[T] { | |
type CompanionT | |
def provide: CompanionT | |
}; object CompanionProvider { | |
def apply[T](implicit c: CompanionProvider[T]): c.CompanionT = c.provide | |
} | |
object Foo { | |
def foo = "fooooo" | |
implicit val companionProvider = new CompanionProvider[Foo] { | |
override type CompanionT = Foo.type | |
override def provide: Foo.type = Foo | |
} | |
}; class Foo | |
class Indirection[T](implicit val c: CompanionProvider[T]) { | |
def indirect: c.CompanionT = c.provide | |
} | |
class Indirection2[T] { | |
def indirect(implicit c: CompanionProvider[T]): c.CompanionT = c.provide | |
} | |
// works | |
CompanionProvider[Foo].foo | |
// error: value foo is not a member of _1.c.CompanionT | |
new Indirection[Foo].indirect.foo | |
// works | |
new Indirection2[Foo].indirect.foo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://issues.scala-lang.org/browse/SI-6139