This is a matter of compiler stages.
Semantic analysis of type declarations at the class level happens early in the compilation process. This includes ivar declarations derived from method signatures (@name : String).
After that the compiler starts analyzing the main program. The body of a method is only visited when there’s a call to this method. At this point, the compiler already needs to know the shape of the type, i.e. which instance variables are defined.
I suppose it might technically be possible to extract ivar type declarations from method bodies in an earlier stage, similar to how it works with type declarations at the class level. In your example, the compiler could potentially derive the necessary information from the method body ahead of time. But there would be a number of caveats to that. And it makes the compiler more complex, with little benefit.
You need to declare instance variables at class level or via the convenience syntax for method parameters.