syntax: extends 'as' and 'isa' warning to nullable
authorJean Privat <jean@pryen.org>
Thu, 18 Jun 2009 20:45:03 +0000 (16:45 -0400)
committerJean Privat <jean@pryen.org>
Wed, 24 Jun 2009 20:03:37 +0000 (16:03 -0400)
Example
  var x: nullable T
  var y = x.as(T) # Bad form
  var y = x.as(not null) # Good form
  if x isa T then ... # Bad form
  if x != null then ... # Good form

Signed-off-by: Jean Privat <jean@pryen.org>

src/syntax/typing.nit

index 8e48ddf..d070119 100644 (file)
@@ -1578,6 +1578,12 @@ special PExpr
                        v.warning(self, "Warning: Expression is already a {ttype}.")
                else if etype < ttype then
                        v.warning(self, "Warning: Expression is already a {ttype} since it is a {etype}.")
+               else if etype.is_nullable and etype.as_notnull == ttype then
+                       if self isa AIsaExpr then
+                               v.warning(self, "Warning: Prefer '!= null'.")
+                       else
+                               v.warning(self, "Warning: Prefer '.as(not null)'.")
+                       end
                end
        end
 end