Skip to content

Ambiguous overload detection bug #14582

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
pootow opened this issue Feb 28, 2022 · 2 comments · Fixed by #17511
Closed

Ambiguous overload detection bug #14582

pootow opened this issue Feb 28, 2022 · 2 comments · Fixed by #17511

Comments

@pootow
Copy link

pootow commented Feb 28, 2022

Compiler version

Scala ( from 3.0.0 to 3.1.2-RC1 )

Minimized code

val map = Map(
  "a" -> 1,
  "b" -> 2
)

val mapView = map.view

val optionMapView = Some(mapView)

val listOfTuples: List[(String, String)] = List(("c", "d"), ("e", "f"))

val mapViewWithDefault = optionMapView.getOrElse(Map())

val result = mapViewWithDefault ++ listOfTuples

println(result.toSeq)

Output

On scala 2, it prints List((a,1), (b,2), (c,d), (e,f)), but on scala 3, it gives a compile error:

Ambiguous overload. The overloaded alternatives of method ++ in trait IterableOps with types
 [B >: (String | Nothing, Int)](suffix: IterableOnce[B]): Iterable[B]
 [B >: (String | Nothing, Int)](suffix: IterableOnce[B]): Iterable[B]
both match arguments ((Playground.listOfTuples : List[(String, String)]))

Here is the scastie of this code snippet: https://scastie.scala-lang.org/P0gdvfw8Qg2cGnOcL0bAwg

Expectation

Compiles with no error.

@pootow pootow added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 28, 2022
@som-snytt
Copy link
Contributor

Thanks for transferring from old repo, where I noted only

scala> val mapViewWithDefault = optionMapView.getOrElse(Map())
val mapViewWithDefault:
  scala.collection.MapOps[? >: String & Nothing <: String | Nothing, Int, [X0, X1] =>> scala.collection.View[(X0, X1)] | Map[X0, X1],
    scala.collection.View[(String, Int)]
   | Map[Nothing, Nothing]]
 & Iterable[(String, Int) | (Nothing, Nothing)] = MapView(<not computed>)

and workaround

scala> val mapViewWithDefault = optionMapView.getOrElse(Map.empty[String, Int])
val mapViewWithDefault:
  scala.collection.MapOps[String, Int, [X0, X1] =>> scala.collection.View[(X0, X1)] | Map[X0, X1], scala.collection.View[(String, Int)] |
    Map[String, Int]
  ]
 & Iterable[(String, Int)] = MapView(<not computed>)

scala> val result = mapViewWithDefault ++ listOfTuples
val result: Iterable[(String, Matchable)] = View(<not computed>)

@prolativ prolativ removed the stat:needs triage Every issue needs to have an "area" and "itype" label label Mar 9, 2022
@odersky
Copy link
Contributor

odersky commented Mar 12, 2022

Would be good to get a minimization that does not use the standard library.

ckipp01 added a commit to ckipp01/dotty that referenced this issue May 15, 2023
nicolasstucki added a commit that referenced this issue May 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants