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 errors overriding implicit vals #5348

Open
scabug opened this issue Dec 29, 2011 · 2 comments
Open

Type errors overriding implicit vals #5348

scabug opened this issue Dec 29, 2011 · 2 comments

Comments

@scabug
Copy link

scabug commented Dec 29, 2011

This is a suite of confusing compilation errors related to overriding of implicit vals. These all appear to be related to some combination of type inference and implicit conversions. Specific error messages accompany the attached source files.

These examples are derived from an example where an implicit conversion required to transform the constructor argument to a case class was not being found, similar to that shown in Broken1.scala; however, in the original failure case (which I have been unsuccessful in attempting to reduce) the implicit conversion A => B appeared to not be found in scope; here is the original failure message:

[error] /Users/nuttycom/reportgrid/blueeyes/src/test/scala/blueeyes/core/service/engines/HttpServerNettySpec.scala:40: type mismatch;
[error]  found   : org.specs2.time.Duration
[error]  required: akka.util.Duration
[error]   implicit val defaultFutureTimeouts = FutureTimeouts(50, duration)

Here are the relevant lines from that example:

trait AkkaConversions {
  implicit def specsDuration2Akka(duration: org.specs2.time.Duration): akka.util.Duration = new DurationLong(duration.inMillis).millis
}

trait FutureMatchers extends AkkaConversions { 
  import akka.util.duration._
  case class FutureTimeouts(retries: Int, duration: akka.util.Duration)

  implicit val defaultFutureTimeouts: FutureTimeouts = FutureTimeouts(10, 100L millis)
  // ...snipped
}

class HttpServerNettySpec extends Specification with BijectionsByteArray with BijectionsChunkString with blueeyes.bkka.AkkaDefaults with FutureMatchers {
  val duration: org.specs2.time.Duration = 350.milliseconds
  override implicit val defaultFutureTimeouts = FutureTimeouts(50, duration)
  // ...snipped
}

In this case, changing HttpServerNettySpec to the following allows compilation to succeed; the implicit conversion is found correctly:

class HttpServerNettySpec extends Specification with BijectionsByteArray with BijectionsChunkString with blueeyes.bkka.AkkaDefaults with FutureMatchers {
  val duration: org.specs2.time.Duration = 350.milliseconds
  implicit val testTimeouts = FutureTimeouts(50, duration)
  // ...snipped
}
@scabug
Copy link
Author

scabug commented Dec 29, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5348?orig=1
Reporter: Kris Nuttycombe (nuttycom)
Affected Versions: 2.9.1
See #2742
Attachments:

  • Broken1.scala (created on Dec 29, 2011 10:22:19 PM UTC, 426 bytes)
  • Broken2.scala (created on Dec 29, 2011 10:22:19 PM UTC, 438 bytes)
  • Broken3.scala (created on Dec 29, 2011 10:22:19 PM UTC, 574 bytes)

@scabug
Copy link
Author

scabug commented May 8, 2012

@adriaanm said:
return type inference for implicit defs should be a language feature you opt-in to

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@scala scala deleted a comment from scabug Mar 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant