Skip to content

trivial lazy self-reference deadlocks on reference ... can we detect this case? #12943

@tpolecat

Description

@tpolecat

Compiler version

3.0.0

Minimized code

scala> lazy val a: Int = a                                                                          
lazy val a: Int

scala> a         
<hangs>

Suggestion

In Scala 2 this situation results in a stack overflow, but in Scala 3 it hangs awaiting an object monitor. It also happens with given values that reference themselves directly, which seem to desugar to a lazy val. I ran into this when someone new to doobie was trying to bring an instance into scope by saying

given Meta[Json] = Meta[Json]

and his program deadlocked trying to summon the instance. This ends up being a common beginner mistake.

In any case my suggestion is that we detect at least this specific case at compile time because it can be very hard to track down.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions