From: Jean Privat Date: Mon, 5 Jan 2015 03:00:27 +0000 (-0500) Subject: typing&engines: accept `is_same_instance` on `null` X-Git-Tag: v0.7.1~45^2~2 X-Git-Url: http://nitlanguage.org typing&engines: accept `is_same_instance` on `null` Signed-off-by: Jean Privat --- diff --git a/src/compiler/global_compiler.nit b/src/compiler/global_compiler.nit index 94dda37..9f082df 100644 --- a/src/compiler/global_compiler.nit +++ b/src/compiler/global_compiler.nit @@ -434,7 +434,7 @@ class GlobalCompilerVisitor if args.first.mcasttype isa MNullableType or args.first.mcasttype isa MNullType and consider_null then # The reciever is potentially null, so we have to 3 cases: ==, != or NullPointerException self.add("if ({args.first} == NULL) \{ /* Special null case */") - if m.name == "==" then + if m.name == "==" or m.name == "is_same_instance" then assert res != null if args[1].mcasttype isa MNullableType then self.add("{res} = ({args[1]} == NULL);") diff --git a/src/compiler/separate_compiler.nit b/src/compiler/separate_compiler.nit index e5f1bb9..297b1ba 100644 --- a/src/compiler/separate_compiler.nit +++ b/src/compiler/separate_compiler.nit @@ -1115,7 +1115,7 @@ class SeparateCompilerVisitor var maybenull = (recv.mcasttype isa MNullableType or recv.mcasttype isa MNullType) and consider_null if maybenull then self.add("if ({recv} == NULL) \{") - if mmethod.name == "==" then + if mmethod.name == "==" or mmethod.name == "is_same_instance" then res = self.new_var(bool_type) var arg = arguments[1] if arg.mcasttype isa MNullableType then diff --git a/src/interpreter/naive_interpreter.nit b/src/interpreter/naive_interpreter.nit index 4bbe635..5cc3892 100644 --- a/src/interpreter/naive_interpreter.nit +++ b/src/interpreter/naive_interpreter.nit @@ -458,7 +458,7 @@ class NaiveInterpreter fun send_commons(mproperty: MMethod, args: Array[Instance], mtype: MType): nullable Instance do if mtype isa MNullType then - if mproperty.name == "==" then + if mproperty.name == "==" or mproperty.name == "is_same_instance" then return self.bool_instance(args[0] == args[1]) else if mproperty.name == "!=" then return self.bool_instance(args[0] != args[1]) diff --git a/src/semantize/typing.nit b/src/semantize/typing.nit index e283b43..1d694e6 100644 --- a/src/semantize/typing.nit +++ b/src/semantize/typing.nit @@ -267,7 +267,7 @@ 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 == "!=" then + if name == "==" or name == "!=" or name == "is_same_instance" then unsafe_type = mmodule.object_type.as_nullable else self.error(node, "Error: Method '{name}' call on 'null'.")