Skip to content

Commit

Permalink
nit: make unreachable statement a warning
Browse files Browse the repository at this point in the history
Signed-off-by: Jean Privat <[email protected]>
  • Loading branch information
privat committed Jun 27, 2024
1 parent 5c7fb2a commit 701694a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/semantize/flow.nit
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ redef class ABlockExpr
v.enter_visit(e)
else if not v.current_flow_context.is_already_unreachable then
v.current_flow_context.is_already_unreachable = true
v.toolcontext.error(e.hot_location, "Error: unreachable statement.")
v.toolcontext.warning(e.hot_location, "unreachable", "Warning: unreachable statement.")
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/semantize/local_var_init.nit
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ private class LocalVarInitVisitor
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)
var flow = node.after_flow_context
if flow != null then 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
var flow = node.after_flow_context
if flow != null and 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)
Expand Down
4 changes: 1 addition & 3 deletions src/semantize/typing.nit
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,7 @@ private class TypeVisitor
fun set_variable(node: AExpr, variable: Variable, mtype: nullable MType)
do
var flow = node.after_flow_context
assert flow != null

flow.set_var(self, variable, mtype)
if flow != null then flow.set_var(self, variable, mtype)
end

# Find the exact representable most specific common super-type in `col`.
Expand Down

0 comments on commit 701694a

Please sign in to comment.