hello, everyone! My code is like this:
class Hello def initialize() end def go(name : Int32|String = 32) name = "" if name.is_a?(Int32) @name = name end end p = Hello.new p.go()
$ crystal build tmp6.cr
got this weird error:
Showing last frame. Use --error-trace for full trace. In tmp6.cr:7:2 7 | @name = name ^---- Error: can't infer the type of instance variable '@name' of Hello The type of a instance variable, if not declared explicitly with `@name : Type`, is inferred from assignments to it across the whole program. he assignments must look like this: 1. `@name = 1` (or other literals), inferred to the literal's type 2. `@name = Type.new`, type is inferred to be Type 3. `@name = Type.method`, where `method` has a return type annotation, type is inferred from it 4. `@name = arg`, with 'arg' being a method argument with a type restriction 'Type', type is inferred to be Type 5. `@name = arg`, with 'arg' being a method argument with a default value, type is inferred using rules 1, 2 and 3 from it 6. `@name = uninitialized Type`, type is inferred to be Type 7. `@name = LibSome.func`, and `LibSome` is a `lib`, type is inferred from that fun. 8. `LibSome.func(out @name)`, 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 '@name' of Hello
but I think
@name should be
String, is it right?