compiler: no-op for expressions that return no RuntimeVariable
authorJean Privat <jean@pryen.org>
Tue, 16 Jun 2015 14:49:52 +0000 (10:49 -0400)
committerJean Privat <jean@pryen.org>
Tue, 16 Jun 2015 14:49:52 +0000 (10:49 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiler/abstract_compiler.nit

index dbe6fc1..221e628 100644 (file)
@@ -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)