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 Conversion not Found Because of Type Widening #10204

Open
scabug opened this issue Feb 23, 2017 · 4 comments
Open

Implicit Conversion not Found Because of Type Widening #10204

scabug opened this issue Feb 23, 2017 · 4 comments
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Milestone

Comments

@scabug
Copy link

scabug commented Feb 23, 2017

Type widening and implicit resolution does not work well together. The effect is visible if the result of Option.getOrElse must be converted by an implicit conversion. There is a corresponding question on StackOverflow answered by Rex Kerr (http://stackoverflow.com/questions/13186063/option-getorelse-type-mismatch-error), but I did not find a matching issue.

object Test {

  trait Formatable[-T] {
    def format(t: T): String
  }

  object Formatable {
    implicit val stringFormatable: Formatable[String] = s => s
  }

  case class Formatted(string: String)

  object Formatted {
    implicit def formatted[T](t: T)(implicit ev: Formatable[T]): Formatted = Formatted(ev.format(t))
  }

  val a = Option("b")

  // type mismatch;
  //found   : java.io.Serializable
  //required: com.bosch.inst.base.etc.StringInterpolationTest.Formatted
  val formatted: Formatted = a.getOrElse("b")


}
@scabug
Copy link
Author

scabug commented Feb 23, 2017

Imported From: https://issues.scala-lang.org/browse/SI-10204?orig=1
Reporter: Stefan Wachter (swachter)

@scabug
Copy link
Author

scabug commented Mar 15, 2017

@SethTisue said:
I have a feeling this is "not a bug", but someone would have to delve into the spec to be sure. I'm glad to have the ticket to document the issue, but it isn't actionable without an analysis.

@scabug scabug added the quickfix label Apr 7, 2017
@scabug scabug added this to the Backlog milestone Apr 7, 2017
@soronpo
Copy link

soronpo commented Jun 16, 2017

@KuceraMartin
Copy link

Any updates about this? Here is an even more minimized example:

//> using scala 2.13

object MyApp {

  trait Conv
  implicit def convInt(s: Int): Conv = ???
  def f[B >: Int](v: B): B = ???
  def g(c: Conv): Unit = ???
  g(f(42))

}

Output:

[error] type mismatch;
[error]  found   : Any
[error]  required: MyApp.Conv
[error]   g(f(42))
[error]     ^^^^^
Error compiling project (Scala 2.13.11, JVM)
Compilation failed

(compiles in Scala 3)

@SethTisue SethTisue added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Nov 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/)
Projects
None yet
Development

No branches or pull requests

4 participants