question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Possible regression in typer or implicits resolution

See original GitHub issue

Compiler version

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

First bad commit 3ab18a90ac24dba440c498aab6a8f0c763589605

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

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
KacperFKorbancommented, May 16, 2022

Minimized a bit more

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

def test() = {
  func(_ => Box(Seq.empty[String]) )
}

def func[R0](to0: Unit => R0): Unit = ???

trait JsonFormat[T]
object JsonFormat{
  implicit def immSeqFormat: JsonFormat[Seq[String]]  = ???

  implicit def iterableFormat: JsonFormat[Iterable[String]]   = ??? 
}

case class Box[A1: JsonFormat](elem: A1)
0reactions
smartercommented, May 31, 2022

I can’t think of anything, except attempting a partial revert of https://github.com/lampepfl/dotty/commit/3ab18a90ac24dba440c498aab6a8f0c763589605 but even that is beyond what little time I have available right now. It’s unfortunate that we’re finding out about all these regressions now as opposed to when they were introduced or in a few months, timing-wise this is the worst-case scenario and there isn’t anything I can do about it really.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implicit resolution regression in 2.13.x. #10425 - scala/bug
I ran into this while working on a fix for #5340 and #4947. The following compiles in 2.12.2 but fails on 2.13.x (including ......
Read more >
Implicit Scope and Implicit Resolution in Scala - geekAbyte
First one was to view the implicit resolution process as a Function call. The second was to understand the relationship between the type ......
Read more >
The Usefulness of Implicit Regression in Model Quality
Implicit Regression is useful in measuring the constant nature of a measured variable [1]; it helps detect bivariate and multivariate random ...
Read more >
Changes in Implicit Resolution - Scala 3 - EPFL
Implicit resolution uses a new algorithm which caches implicit results more aggressively for performance. There are also some changes that affect implicits on ......
Read more >
Scala type equality and path-dependent types - Stack Overflow
I don't see a reason to introduce type D in method run. Without it method signature looks simpler and successfully compiles
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found