syntax: "!= null" works like a "isa"
authorJean Privat <jean@pryen.org>
Tue, 23 Jun 2009 17:48:46 +0000 (13:48 -0400)
committerJean Privat <jean@pryen.org>
Wed, 24 Jun 2009 20:01:53 +0000 (16:01 -0400)
Signed-off-by: Jean Privat <jean@pryen.org>

src/syntax/typing.nit

index 921ea14..8e48ddf 100644 (file)
@@ -1313,6 +1313,20 @@ redef class AEqExpr
                n_expr2.stype isa MMTypeNone and not n_expr.stype.is_nullable then
                        v.warning(self, "Warning: comparaison between null and a non nullable value.")
                end
+
+               if n_expr.stype isa MMTypeNone then
+                       try_to_isa(v, n_expr2)
+               else if n_expr2.stype isa MMTypeNone then
+                       try_to_isa(v, n_expr)
+               end
+       end
+
+       private meth try_to_isa(v: TypingVisitor, n: PExpr)
+       do
+               var variable = n.its_variable
+               if variable != null then
+                       _if_false_variable_ctx = v.variable_ctx.sub_with(self, variable, n.stype.as_notnull)
+               end
        end
 end
 redef class ANeExpr
@@ -1325,6 +1339,20 @@ redef class ANeExpr
                n_expr2.stype isa MMTypeNone and not n_expr.stype.is_nullable then
                        v.warning(self, "Warning: comparaison between null and a non nullable value.")
                end
+
+               if n_expr.stype isa MMTypeNone then
+                       try_to_isa(v, n_expr2)
+               else if n_expr2.stype isa MMTypeNone then
+                       try_to_isa(v, n_expr)
+               end
+       end
+
+       private meth try_to_isa(v: TypingVisitor, n: PExpr)
+       do
+               var variable = n.its_variable
+               if variable != null then
+                       _if_true_variable_ctx = v.variable_ctx.sub_with(self, variable, n.stype.as_notnull)
+               end
        end
 end
 redef class ALtExpr