syntax: allow 'null == x' and 'null != x'
authorJean Privat <jean@pryen.org>
Fri, 15 Jan 2010 20:49:37 +0000 (15:49 -0500)
committerJean Privat <jean@pryen.org>
Fri, 15 Jan 2010 20:49:37 +0000 (15:49 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/syntax/typing.nit
tests/sav/error_expr_not_ok_alt6.sav

index 980eba8..749d1b7 100644 (file)
@@ -1269,8 +1269,13 @@ redef class AAbsSendExpr
        private fun get_property(v: TypingVisitor, type_recv: MMType, is_implicit_self: Bool, name: Symbol): nullable MMMethod
        do
                if type_recv isa MMTypeNone then
-                       v.error(self, "Error: Method '{name}' call on 'null'.")
-                       return null
+                       if name == (once "==".to_symbol) or name == (once "!=".to_symbol) then
+                               # Special case on != and == that are allowed for 'null'
+                               type_recv = v.type_object.as_nullable
+                       else
+                               v.error(self, "Error: Method '{name}' call on 'null'.")
+                               return null
+                       end
                end
                var lc = type_recv.local_class
                var prop: nullable MMMethod = null
index 0249e8c..857efc5 100644 (file)
@@ -44,12 +44,12 @@ alt/error_expr_not_ok_alt6.nit:78,16--19: Type error: expected Bool, got null
 alt/error_expr_not_ok_alt6.nit:78,7--19: Type error: expected A, got Bool
 alt/error_expr_not_ok_alt6.nit:79,11--14: Type error: expected Bool, got null
 alt/error_expr_not_ok_alt6.nit:79,7--14: Type error: expected A, got Bool
-alt/error_expr_not_ok_alt6.nit:80,7--15: Error: Method '==' call on 'null'.
+alt/error_expr_not_ok_alt6.nit:80,7--15: Type error: expected A, got Bool
 alt/error_expr_not_ok_alt6.nit:81,7--15: Type error: expected A, got Bool
-alt/error_expr_not_ok_alt6.nit:82,7--18: Error: Method '==' call on 'null'.
-alt/error_expr_not_ok_alt6.nit:83,7--15: Error: Method '!=' call on 'null'.
+alt/error_expr_not_ok_alt6.nit:82,7--18: Type error: expected A, got Bool
+alt/error_expr_not_ok_alt6.nit:83,7--15: Type error: expected A, got Bool
 alt/error_expr_not_ok_alt6.nit:84,7--15: Type error: expected A, got Bool
-alt/error_expr_not_ok_alt6.nit:85,7--18: Error: Method '!=' call on 'null'.
+alt/error_expr_not_ok_alt6.nit:85,7--18: Type error: expected A, got Bool
 alt/error_expr_not_ok_alt6.nit:86,7--15: Type error: expected A, got Bool
 alt/error_expr_not_ok_alt6.nit:87,7--15: Type error: expected A, got Bool
 alt/error_expr_not_ok_alt6.nit:88,7--18: Type error: expected A, got Bool