From: Jean Privat Date: Sun, 12 Apr 2015 04:13:24 +0000 (+0700) Subject: compiler: consider untyped expressions and statement as dead code X-Git-Tag: v0.7.4~26^2~5 X-Git-Url: http://nitlanguage.org compiler: consider untyped expressions and statement as dead code Signed-off-by: Jean Privat --- diff --git a/src/astvalidation.nit b/src/astvalidation.nit index b34d42f..2883197 100644 --- a/src/astvalidation.nit +++ b/src/astvalidation.nit @@ -74,7 +74,7 @@ redef class AExpr do super if mtype == null and not is_typed then - debug "TYPING: untyped expression" + #debug "TYPING: untyped expression" end end end diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index 059961f..f579a32 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -1628,6 +1628,12 @@ abstract class AbstractCompilerVisitor fun stmt(nexpr: nullable AExpr) do if nexpr == null then return + if nexpr.mtype == null and not nexpr.is_typed then + # Untyped expression. + # Might mean dead code + # So just return + return + end var narray = nexpr.comprehension if narray != null then @@ -1647,6 +1653,13 @@ abstract class AbstractCompilerVisitor # `mtype` is the expected return type, pass null if no specific type is expected. fun expr(nexpr: AExpr, mtype: nullable MType): RuntimeVariable do + if nexpr.mtype == null then + # Untyped expression. + # Might mean dead code + # so return a placebo result + if mtype == null then mtype = compiler.mainmodule.object_type + return new_var(mtype) + end var old = self.current_node self.current_node = nexpr var res = nexpr.expr(self).as(not null)