compiler: consider untyped expressions and statement as dead code
authorJean Privat <jean@pryen.org>
Sun, 12 Apr 2015 04:13:24 +0000 (11:13 +0700)
committerJean Privat <jean@pryen.org>
Tue, 14 Apr 2015 09:31:36 +0000 (16:31 +0700)
Signed-off-by: Jean Privat <jean@pryen.org>

src/astvalidation.nit
src/compiler/abstract_compiler.nit

index b34d42f..2883197 100644 (file)
@@ -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
index 059961f..f579a32 100644 (file)
@@ -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)