Mapping with a function that takes a using argument in Scala 3.3.7

Just upgraded to Scala 3.3.7 from 3.3.6 and was bitten by this:

case class MergeResult[Element: Eq] private (segments: Seq[Segment[Element]]):

  def fuseWith(another: MergeResult[Element])(
      elementFusion: (Element, Element) => Option[Element]
  ): Option[MergeResult[Element]] =
    if segments.size != another.segments.size then None
    else
      Traverse[Seq]
        .traverse(segments.zip(another.segments))(_.fuseWith(_)(elementFusion))
        .map(MergeResult.apply)
        //               ^^^^^ Can't find the given for Eq[Any], despite there
        //                     being an Eq[Element] available.

This used to compile under 3.3.6.

I’ve worked around this by changing the function application to MergeResult.apply[Element], but was curious - is this, ahem, a bug or feature?

I recall there were changes about given resolution over a hierarchy of types a while back, but I thought type unification would propagate from the explicit return type of Option[MergeResult[Element]] to force pulling in the given for Eq[Element]?

Looks like a bug, I might have been over eager back porting things. Do you know if the same happens with 3.7.3?

It might be caused by Refine implicit search fallbacks for better ClassTag handling by odersky · Pull Request #23532 · scala/scala3 · GitHub

Arrgh - this breaks the project build in umpteen places. Notably, given syntax has changed, multiple context bounds should be enclosed in braces, infix declarations are needed, using is mandatory where it didn’t used to be…

Nevertheless, I can happily report that yes, the same problem occurs in the same place in 3.7.3. :cat_with_wry_smile:

Thanks for taking a look, @tgodzik .

I think most of these have automatic rewrites, we need to create a guide with the next release.

Nevertheless, I can happily report that yes, the same problem occurs in the same place in 3.7.3.

Could you report it as an issue? Someone might sched a light why this changed and whether it was intended. If intended, we should remove the change from LTS

Done: Given definition is no longer resolved to in mapped function usage site. · Issue #24192 · scala/scala3 · GitHub.

Thanks!