typing&engines: accept `is_same_instance` on `null`
authorJean Privat <jean@pryen.org>
Mon, 5 Jan 2015 03:00:27 +0000 (22:00 -0500)
committerJean Privat <jean@pryen.org>
Mon, 5 Jan 2015 03:00:27 +0000 (22:00 -0500)
Signed-off-by: Jean Privat <jean@pryen.org>

src/compiler/global_compiler.nit
src/compiler/separate_compiler.nit
src/interpreter/naive_interpreter.nit
src/semantize/typing.nit

index 94dda37..9f082df 100644 (file)
@@ -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);")
index e5f1bb9..297b1ba 100644 (file)
@@ -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
index 4bbe635..5cc3892 100644 (file)
@@ -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])
index e283b43..1d694e6 100644 (file)
@@ -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'.")