Skip to content

infinite loop when evaluating a recursive given definition #10947

Closed
@Swoorup

Description

@Swoorup

When running a program which consumes opaque types as follows, it appears to be stuck on an infinite loop. Not sure what is going on here.

Minimized code

object Prices {
  opaque type Price = BigDecimal

  object Price{
    given Ordering[Price] = summon[Ordering[BigDecimal]]
  }

}

extension[K,V] (m1: Map[K,V]) def computeDiff(m2: Map[K,V])(using Ordering[K])(using orderAsc: Boolean = true): Unit = println("Ok....")

import Prices._
@main def mainz = {
    println("begin")
    val result = Map.empty[Price,Int].computeDiff(Map.empty[Price,Int])
    println(s"end $result")
}

Scastie link: https://scastie.scala-lang.org/ajEagvzvTbitmzbqFt0Oxw

Output

begin

Expectation

Should successfully print the following:

begin
Ok....
end

This works if the Price was swapped with BigDecimal in the line

  val result = Map.empty[Price,Int].computeDiff(Map.empty[Price,Int])

This is happening on 3.0.0-M3

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions