What's the reason why Crystal can't/won't resolve the type of this? (I see that the documentation does not mention that the compiler could infer instance method calls, but what's the rationale behind it, especially when only stdlib functions are involved? Compile time?)
class Something
def blah
@result = 1 + 1
end
end
Something.new().blah
Compiler error:
Showing last frame. Use --error-trace for full trace.
error in line 3
Error: can't infer the type of instance variable '@result' of SomeObject
The type of a instance variable, if not declared explicitly with
`@result : Type`, is inferred from assignments to it across
the whole program.
The assignments must look like this:
1. `@result = 1` (or other literals), inferred to the literal's type
2. `@result = Type.new`, type is inferred to be Type
3. `@result = Type.method`, where `method` has a return type
annotation, type is inferred from it
4. `@result = arg`, with 'arg' being a method argument with a
type restriction 'Type', type is inferred to be Type
5. `@result = arg`, with 'arg' being a method argument with a
default value, type is inferred using rules 1, 2 and 3 from it
6. `@result = uninitialized Type`, type is inferred to be Type
7. `@result = LibSome.func`, and `LibSome` is a `lib`, type
is inferred from that fun.
8. `LibSome.func(out @result)`, and `LibSome` is a `lib`, type
is inferred from that fun argument.
Other assignments have no effect on its type.
can't infer the type of instance variable '@result' of SomeObject