From 82422f31e490a02b083757682abaeef44712519e Mon Sep 17 00:00:00 2001 From: Jean Privat Date: Wed, 27 May 2015 19:23:13 -0400 Subject: [PATCH] typing: use `is_null_safe` Because it is done on the property, the test must be done latter. Signed-off-by: Jean Privat --- src/semantize/typing.nit | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) 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 -- 1.7.9.5