From: Jean Privat Date: Wed, 27 May 2015 23:23:13 +0000 (-0400) Subject: typing: use `is_null_safe` X-Git-Tag: v0.7.5~4^2~3 X-Git-Url: http://nitlanguage.org typing: use `is_null_safe` Because it is done on the property, the test must be done latter. Signed-off-by: Jean Privat --- diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index c26ca0f..ada6160 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -301,15 +301,9 @@ private class TypeVisitor #debug("recv: {recvtype} (aka {unsafe_type})") if recvtype isa MNullType then - # `null` only accepts some methods of object. - if name == "==" or name == "!=" or name == "is_same_instance" then - var objclass = get_mclass(node, "Object") - if objclass == null then return null # Forward error - unsafe_type = objclass.mclass_type - else - self.error(node, "Error: method `{name}` called on `null`.") - return null - end + var objclass = get_mclass(node, "Object") + if objclass == null then return null # Forward error + unsafe_type = objclass.mclass_type end var mproperty = self.try_get_mproperty_by_name2(node, unsafe_type, name) @@ -331,6 +325,12 @@ private class TypeVisitor assert mproperty isa MMethod + # `null` only accepts some methods of object. + if recvtype isa MNullType and not mproperty.is_null_safe then + self.error(node, "Error: method `{name}` called on `null`.") + return null + end + if is_toplevel_context and recv_is_self and not mproperty.is_toplevel then error(node, "Error: `{name}` is not a top-level method, thus need a receiver.") end