From fd97f5a93854e22ab58756dd9760aaa4351de13b Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Tue, 16 Jun 2015 10:49:52 -0400 Subject: [PATCH] compiler: no-op for expressions that return no RuntimeVariable Signed-off-by: Jean Privat --- src/compiler/abstract_compiler.nit | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/compiler/abstract_compiler.nit b/src/compiler/abstract_compiler.nit index dbe6fc1..221e628 100644 --- a/src/compiler/abstract_compiler.nit +++ b/src/compiler/abstract_compiler.nit @@ -1696,18 +1696,27 @@ 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 + var old = self.current_node + self.current_node = nexpr + + var res = null + if nexpr.mtype != null then + res = nexpr.expr(self) + end + + if res == null then # Untyped expression. # Might mean dead code or invalid code. # so aborts add_abort("FATAL: bad expression executed.") # and return a placebo result to please the C compiler if mtype == null then mtype = compiler.mainmodule.object_type - return new_var(mtype) + res = new_var(mtype) + + self.current_node = old + return res end - var old = self.current_node - self.current_node = nexpr - var res = nexpr.expr(self).as(not null) + if mtype != null then mtype = self.anchor(mtype) res = self.autobox(res, mtype) -- 1.7.9.5