Skip to content

Possible regression in typer or implicits resolution #15184

Closed
@WojciechMazur

Description

@WojciechMazur

Compiler version

3.1.2
Works in 3.1.1
Fails in 3.2.0-RC1-bin-20220512-9dbe2d3-NIGHTLY

First bad commit 3ab18a9

Minimized code

Based on https://github.com/eed3si9n/sjson-new/blob/3c8e15b504145de07b9a46a87a21b85fbdd97c53/support/scalajson/src/test/scala/sjsonnew/support/scalajson/unsafe/LListFormatSpec.scala#L11-L16

Might need further minimization

//> using scala "3.1.2"
// //> using scala "3.1.1" // Last working stable version

def test() = {
  given JsonFormat[LCons[Seq[String], LNil]] = ???
  case class Foo(xs: Seq[String])
  implicit val isoLList: IsoLList[Foo] = LList.isoCurried((a: Foo) => "xs" -> a.xs :*: LNil ){ 
    case (_, xs) :*: LNil => Foo(xs) 
  }
}

trait JsonFormat[T]
object JsonFormat{
  import collection.{immutable => imm}
  implicit def immSeqFormat[T :JsonFormat]: JsonFormat[imm.Seq[T]]  = ???

  import collection._
  implicit def iterableFormat[T :JsonFormat]: JsonFormat[Iterable[T]]   = ??? 

  given JsonFormat[String] = ???
}

sealed trait LList
object LList{
  val LNil0: LNil0 = new LNil0 {}
  sealed trait LNil0 extends LList {
    def :*:[A1: JsonFormat](labelled: (String, A1)): LCons[A1, LNil] = ???
  }
  def isoCurried[A, R0 <: LList: JsonFormat](to0: A => R0)(from0: R0 => A): IsoLList.Aux[A, R0] = ???
}
type LNil = LList.LNil0
val LNil = LList.LNil0

final class LCons[A1: JsonFormat, A2 <: LList: JsonFormat] extends LList
type :*:[A1, A2 <: LList] = LCons[A1, A2]
object :*: {
  def unapply[H, T <: LList](x: H :*: T): Some[((String, H), T)] = ???
}

trait IsoLList[A]
object IsoLList {
  type Aux[A, R0] = IsoLList[A]{ type R = R0 }
}

Output

[error] ./test.scala:40:92: ambiguous implicit arguments: both method immSeqFormat in object JsonFormat and method iterableFormat in object JsonFormat match type JsonFormat[(avoid)A1] of an implicit parameter of method :*: in trait LNil0
[error]   implicit val isoLList: IsoLList[Foo] = LList.isoCurried((a: Foo) => "xs" -> a.xs :*: LNil ){ 
[error]                                                                                            ^
Error compiling project (Scala 3.1.2, JVM)

Expectation

Should correctly resolve correct implicit, in 3.1.1 compiler choosed JsonFormat.immSeqFormat

Metadata

Metadata

Assignees

Labels

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

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions