From d084ef374360fd480466b75112919619a3c40ffa Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Sun, 12 Apr 2015 11:13:24 +0700 Subject: [PATCH] compiler: consider untyped expressions and statement as dead code Signed-off-by: Jean Privat --- src/astvalidation.nit | 2 +- src/compiler/abstract_compiler.nit | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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) -- 1.7.9.5