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

Implicit conversions fail when overriding implicit val from super trait #6780

Closed
scabug opened this issue Dec 6, 2012 · 4 comments
Closed

Implicit conversions fail when overriding implicit val from super trait #6780

scabug opened this issue Dec 6, 2012 · 4 comments
Assignees
Milestone

Comments

@scabug
Copy link

@scabug scabug commented Dec 6, 2012

Consider this:
{code}import scala.concurrent.duration._

trait Foo { implicit val timeout = 1 second }
trait Bar extends Foo { implicit override val timeout = 2 seconds }

In 2.10.0-RC2 and 2.10.0-RC3, the implicit conversion that gives the seconds method to Int fails:

Welcome to Scala version 2.10.0-RC3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
Type in expressions to have them evaluated.
Type :help for more information.

scala> :load foo.scala
Loading foo.scala...
import scala.concurrent.duration._
warning: there were 1 feature warnings; re-run with -feature for details
defined trait Foo
:11: error: value seconds is not a member of Int
trait Bar extends Foo { implicit override val timeout = 2 seconds }
^
{code}

When the implicit keyword is removed from the overridden val, the implicit conversion works properly.

@scabug
Copy link
Author

@scabug scabug commented Dec 6, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6780?orig=1
Reporter: Michael Pilquist (mpilquist)
Affected Versions: 2.10.0-RC2, 2.10.0-RC3

@scabug
Copy link
Author

@scabug scabug commented Dec 6, 2012

@paulp said:
For some reason if the overriding implicit is typed without an expected type, the failure is reported. It looks to me like it proceeds to type the override with an expected type of Int, at which point it finds the implicit, but it's too late. Supposed to be a silent context being used somewhere?

import scala.concurrent.duration._

trait Foo { implicit val v: Duration = 1.seconds }
trait Bar1 extends Foo { override implicit val v = 2.seconds } // fails
trait Bar2 extends Foo { override implicit val v: Duration = 2.seconds } // compiles

@scabug
Copy link
Author

@scabug scabug commented Dec 11, 2013

@retronym said:
I'm looking into this. My test case:

object O {
  implicit def i: Int = 0
}

import O._
 
trait Foo {
  implicit val v1: Any
  implicit val d1: Any
           val v2: Any
  implicit val v3: Any
}

trait Bar1 extends Foo {
  implicit val v1      = {implicitly[Int]; ()} // fail
           def d1      = {implicitly[Int]; ()} // okay
  implicit val v2      = {implicitly[Int]; ()} // okay
  implicit val v3: Any = {implicitly[Int]; ()} // okay

}

@scabug
Copy link
Author

@scabug scabug commented Dec 11, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants