infinite loop when evaluating a recursive given definition
See original GitHub issueWhen 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
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (2 by maintainers)
Top Results From Across the Web
Infinite loop - Wikipedia
Infinite recursion is a special case of an infinite loop that is caused by recursion. The following example in VBA returns a stack...
Read more >what is the difference between while(1) infinite loop and a ...
A recursive function keeps calling itself whereas an infinite loop keeps repeating the same block of code. When a function ...
Read more >Recursion and Looping | Baeldung on Computer Science
In simple terms, we can define looping or iteration as the process where the same set of instructions is repeated multiple times in...
Read more >15-150 Lecture 3: Recursion; Structural Induction
I.e. it is an infinite loop. 1.2 Case case is a new operation on natural numbers. It lets you distinguish whether the number...
Read more >If Statements, Loops and Recursion - OCaml
Now we come to a hard topic - recursion. Functional programmers are defined by their love of recursive functions, and in many ways...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@tel I really wish this was possible. I don’t see people switching from
@newtype
to opaque types anytime soon if this isn’t made easier - I just bumped on the issue at question myself and the boilerplate needed to do it “properly” is very discouraging.We could enhance the initialization check to check for possible non-termination of lazy fields. A related issue #9668.