implicit conversion does not favor by-value conversions first, unlike Scala 2
See original GitHub issueclass 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:
- Created 7 years ago
- Comments:7 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@felixmulder I’ve replaced your example with a minimized version and changed the title to reflect the real problem.
What about using the old rule under
-language:Scala2
?