From: Jean Privat Date: Thu, 18 Jun 2009 20:45:03 +0000 (-0400) Subject: syntax: extends 'as' and 'isa' warning to nullable X-Git-Tag: v0.3~220 X-Git-Url: http://nitlanguage.org syntax: extends 'as' and 'isa' warning to nullable 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 --- diff --git a/src/syntax/typing.nit b/src/syntax/typing.nit index 8e48ddf..d070119 100644 --- a/src/syntax/typing.nit +++ b/src/syntax/typing.nit @@ -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