private class LocalVarInitVisitor
super Visitor
var toolcontext: ToolContext
# Local variables that are possibly unset (ie local variable without an initial value)
var maybe_unset_vars: Set[Variable] = new HashSet[Variable]
fun mark_is_unset(node: AExpr, variable: nullable Variable)
do
assert variable != null
self.maybe_unset_vars.add(variable)
end
fun mark_is_set(node: AExpr, variable: nullable Variable)
do
assert variable != null
if not maybe_unset_vars.has(variable) then return
var flow = node.after_flow_context.as(not null)
flow.set_vars.add(variable)
end
fun check_is_set(node: AExpr, variable: nullable Variable)
do
assert variable != null
if not maybe_unset_vars.has(variable) then return
var flow = node.after_flow_context.as(not null)
if not flow.is_variable_set(variable) then
self.toolcontext.error(node.hot_location, "Error: possibly unset variable `{variable}`.")
# Remove the variable to avoid repeating errors
self.maybe_unset_vars.remove(variable)
end
end
redef fun visit(n)
do
n.accept_local_var_visitor(self)
end
end
src/semantize/local_var_init.nit:43,1--83,3