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
Recursive implicit view should yield lint warning #8357
Comments
Imported From: https://issues.scala-lang.org/browse/SI-8357?orig=1 |
@adriaanm said (edited on Mar 3, 2014 9:31:16 PM UTC): This will also loop: trait Foo
trait Sizeable { def size: Int }
implicit def fooHasSize[T](gto: T)(implicit ev: T => Foo): Sizeable = ev(gto)
fooHasSize(new Foo{}) -Xprint:typer reveals why: implicit def fooHasSize[T](gto: T)(implicit ev: T => Foo): Sizeable
= fooHasSize[Foo](ev.apply(gto))(Predef.$conforms[Foo]) |
Tomer Gabel (holograph) said (edited on Mar 3, 2014 7:58:12 PM UTC): |
@retronym said (edited on Mar 3, 2014 8:24:45 PM UTC): This has a unintended interaction with structural types: trait T extends Any {
def size: Int
}
object Test {
type Structural = { def size: Int }
def foo(x: T): Structural = x
}
Because of this, your the result of // -Xprint:typer
implicit def hasSize[T](gto: T)(implicit ev: T => scala.collection.GenTraversableOnce[_]): Test.Structural = {
val temp: scala.collection.GenTraversableOnce[Any] = ev.apply(gto);
Test.this.hasSize[scala.collection.GenTraversableOnce[Any]](temp)(scala.this.Predef.$conforms[scala.collection.GenTraversableOnce[Any]])
}; Workaround: type Structural = Any { def size: Int } (The "naked" |
Tomer Gabel (holograph) said: |
@retronym said: |
Tomer Gabel (holograph) said: |
@adriaanm said: |
@adriaanm said: |
Meir Maor (meirmaor) said: implicit def genericTraversableOnce2HasSize[ T ]( gto: T )( implicit ev: T => AnyRef with GenTraversableOnce[_] ): Structural = ev( gto ) |
The temptation is to upgrade the message to: |
Apparently structural types and implicit conversions don't play along very well; see the following repro (directly runnable on the Scala console):
I couldn't tell you why, but this works around the problem:
This makes no sense though, because the
conforms
call should result in exactly the same behavior. Any help would be appreciated...The text was updated successfully, but these errors were encountered: