Skip to content

Given definition is no longer resolved to in mapped function usage site. #24192

@sageserpent-open

Description

@sageserpent-open

Compiler version

3.3.7 (also seen in 3.7.3)

Minimized code

//> using scala 3.3.7
//> using options -Wall -Werror

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.

Output

No given instance of type cats.kernel.Eq[Any] was found for a context parameter of method apply in object MergeResult
        .map(MergeResult.apply)

Expectation

This used to build under 3.3.6, now fails because the given for Eq[Element] is not used, rather a search for Eq[Any] takes place.

My expectation was that the explicit return type of Option[Element] should have forced the correct resolution of the given.

NOTE: changing the function application to MergeResult.apply[Element] works around this problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:implicitsrelated to implicitsitype:bugregressionThis worked in a previous version but doesn't anymore

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions