Very odd error [0.35.1]

Using Repl.it, link is here but was wondering why I’m getting an error:

Error: this 'initialize' doesn't explicitly initialize instance variable '@expression' of Stmt::Print, rendering it nilable

Here’s the code it refers to, to save you a click:

abstract class Stmt
...
 class Print < Stmt
   getter name
   getter initializer
   def initialize(@name : Token, @initializer : Expr); end
   def accept(visitor : Stmt::Visitor(R)) : R forall R
     visitor.visitPrintStmt self
   end
 end
...
end

I generated this code using a tool script, so I have no idea what the compiler is even talking about. There is no @expression. Any ideas?

I see this in the code…

 class Print < Stmt
   getter expression
   def initialize(@expression : Expr); end
   def accept(visitor : Stmt::Visitor(R)) : R forall R
     visitor.visitPrintStmt self
   end
 end
 class Print < Stmt
   getter name
   getter initializer
   def initialize(@name : Token, @initializer : Expr); end
   def accept(visitor : Stmt::Visitor(R)) : R forall R
     visitor.visitPrintStmt self
   end
 end

:confused: wow that’s a little embarassing, what did I do there? I seem to have misnamed an AST, haha. You have a good eye, thank you!

1 Like

Glad to help! :slight_smile:

1 Like