SLS (Scala Language Specification) says, at https://scala-lang.org/files/archive/spec/3.4/04-basic-definitions.html ,
The scope of a name introduced by a definition is the whole statement sequence containing the definition. However, there is a restriction on forward references in blocks [...]
So this seems to be working as designed, but it isn't clear to me why it's specified this way. Why "the whole statement sequence" rather than "the following statements"?