Skip to content

Incorrect warning about ambiguous implicit #20572

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

Closed
OlegYch opened this issue Jun 14, 2024 · 2 comments · Fixed by #21045
Closed

Incorrect warning about ambiguous implicit #20572

OlegYch opened this issue Jun 14, 2024 · 2 comments · Fixed by #21045
Labels
area:implicits related to implicits area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug

Comments

@OlegYch
Copy link
Contributor

OlegYch commented Jun 14, 2024

Compiler version

3.5.0-RC1-3.5.1-RC1-bin-20240613-61a15b2-NIGHTLY

Minimized code

can't really minimize, but i hope the error message is enough
here is an approximation but for some reason it doesn't produce a warning:
https://scastie.scala-lang.org/OlegYch/io8Z28sZTC2qIUA3lqJtSw/36

Output

instead i get a warning:

[warn] 124 |              "metal"      -> Money[CurrencyCode.Any](1, CurrencyCode.Gold),
[warn]     |                                                                           ^
[warn]     |Given search preference for play.api.libs.json.Writes[com.Money[com.CurrencyCode.CurrencyValue]] between alternatives (com.Money._MoneyFormat :
[warn]     |  [C <: com.CurrencyCode.Any]
[warn]     |    (implicit evidence$1: play.api.libs.json.Format[C]): play.api.libs.json.Format[com.Money[C]]
[warn]     |) and (play.api.libs.json.Writes.enumNameWrites :
[warn]     |  [E <: Enumeration](using e: ValueOf[E]): play.api.libs.json.Writes[e.value.Value]) will change
[warn]     |Current choice           : the first alternative
[warn]     |New choice from Scala 3.6: none - it's ambiguous

for some reason it tries to apply enumNameWrites from play, but it's only applicable for scala.Enumeration, not enumeratum

Expectation

no warning

@OlegYch OlegYch added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 14, 2024
@OlegYch
Copy link
Contributor Author

OlegYch commented Jun 24, 2024

i was able to minimize it (using 3.5.0-RC2):

trait Writes[T]
trait Format[T] extends Writes[T]
given [T: List]: Writes[T] = null
given [T]: Format[T] = null

summon[Writes[Int]]

gives

Given search preference for Playground.Writes[Int] between alternatives (Playground.given_Format_T : [T]: Playground.Format[T]) and (Playground.given_Writes_T :
  [T](implicit evidence$1: List[T]): Playground.Writes[T]) will change
Current choice           : the first alternative
New choice from Scala 3.6: the second alternative

https://scastie.scala-lang.org/OlegYch/io8Z28sZTC2qIUA3lqJtSw/146

@Gedochao Gedochao added area:reporting Error reporting including formatting, implicit suggestions, etc area:implicits related to implicits and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jun 25, 2024
@mrdziuban
Copy link

mrdziuban commented Jul 1, 2024

I've just run into this on Scala 3.5.0-RC2 as well with circe -- https://scastie.scala-lang.org/jVQZCmzbRFaKxJk6AroUsw

import io.circe.Encoder

case class Foo[A]() derives Encoder
case class Bar[A](foo: Foo[A]) derives Encoder

yields an error

Given search preference for io.circe.Encoder[Playground.Foo[A]] between alternatives (Playground.Foo.derived$Encoder :
  [A²](implicit x$0: io.circe.Encoder[A²]): io.circe.Encoder[Playground.Foo[A²]]
  ) and (io.circe.Encoder.encodeIterable :
  [A², C[_$20]]
    (implicit encodeA: io.circe.Encoder[A²], ev: C[A²] => Iterable[A²]):
      io.circe.Encoder.AsArray[C[A²]]
) will change
Current choice           : none - it's ambiguous
New choice from Scala 3.6: the first alternative

where:    A  is a type in given instance derived$Encoder²
          A² is a type variable

odersky added a commit to dotty-staging/dotty that referenced this issue Jul 5, 2024
odersky added a commit to dotty-staging/dotty that referenced this issue Jul 5, 2024
EugeneFlesselle added a commit to dotty-staging/dotty that referenced this issue Jul 5, 2024
@odersky odersky closed this as completed in c9b9ad4 Jul 8, 2024
odersky added a commit that referenced this issue Jul 8, 2024
WojciechMazur pushed a commit to WojciechMazur/dotty that referenced this issue Jul 10, 2024
WojciechMazur pushed a commit to WojciechMazur/dotty that referenced this issue Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants