Closed
Description
Compiler version
3.7.0
reproduced also for nightly version (currently 3.7.2-RC1-bin-20250527-2703b6b-NIGHTLY)
Minimized code
//> using scala 3.7.0
enum Test:
case One
case Two(i: Int)
object Test:
object Two:
def apply(i: Int): Test.Two = Test.Two(i)
object app extends App:
Test.Two(1)
Output
run of above code snippet leads to "lock" (execution is stuck)
Expectation
I expected to see at least compiler warning for such code
Activity
som-snytt commentedon May 28, 2025
enum
is not involved, as the method recurses trivially.It works as
It's normal to write a custom
apply
method where one might be generated, such as in a case class companion.The check in Scala 2 warns for only the most trivial definition:
Actually, Scala 3 makes an effort now:
The check in tailrec could be more expansive or forgiving:
The usual observation is, "No one writes code like that, until they do." What does the A.I. say about it?
drewfeelsblue commentedon May 28, 2025
ah, I see now, @som-snytt thank you for the reply
so
compiles just fine
while
warns about recursive call
som-snytt commentedon May 28, 2025
The PR warns despite an assignment to
this
that is a stable (but impure) value; then avoids emitting the assignment for anobject
.[-]Conflicting definitions lead to the endless run[/-][+]Missing warning for Infinite recursive call in object[/+]Warn trivial recursion with module prefix (#23278)
3 remaining items