question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

implicit conversion does not favor by-value conversions first, unlike Scala 2

See original GitHub issue
class A
class B

object Test {
  implicit def a2b(a: A): B = ???
  implicit def byName_a2b(a: => A): B = ???

  def test(a: A): Unit = {
    val b: B = a
  }
}

With scalac, compilation succeeds, and the typechecked tree for test is:

val b: B = Test.this.a2b(a)

But with dotty, it fails with:

-- [E007] Type Mismatch Error: try/ambimp2.scala -------------------------------
9 |    val b: B = a
  |               ^
  |found:    A(a)
  |required: B
  |
  |
  |Note that implicit conversions cannot be applied because they are ambiguous;
  | both method byName_a2b in object Test and method a2b in object Test convert from A(a) to B

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
smartercommented, Feb 21, 2017

@felixmulder I’ve replaced your example with a minimized version and changed the title to reflect the real problem.

0reactions
smartercommented, Feb 22, 2017

What about using the old rule under -language:Scala2 ?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implicit Conversions | Tour of Scala
Implicit conversions are a powerful Scala feature that enable two common use cases: allow users to supply an argument of one type, as...
Read more >
by-name impl conv of Nothing type fails compiler #1397 - GitHub
i have an in-scope implicit conversion for (=> Nothing) type but the compiler errors instead of applying it. say i have these implicit...
Read more >
generics - Scala selects wrong implicit conversion from within ...
Implicit resolution is "dispatched" in compile time so it only can access (type) information available to the compiler in particular place.
Read more >
Implicit Conversions | Baeldung on Scala
Implicit conversions give the Scala compiler the ability to convert one type into another. We can also use them to add additional methods...
Read more >
Implicit Conversions - More Details - Scala 3
An implicit conversion, or view, from type S to type T is defined by either: ... In Scala 2, views whose parameters are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found