Signed-off-by: Jean Privat <jean@pryen.org>
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 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 == "==" or m.name == "is_same_instance" then
assert res != null
if args[1].mcasttype isa MNullableType then
self.add("{res} = ({args[1]} == NULL);")
assert res != null
if args[1].mcasttype isa MNullableType then
self.add("{res} = ({args[1]} == NULL);")
var maybenull = (recv.mcasttype isa MNullableType or recv.mcasttype isa MNullType) and consider_null
if maybenull then
self.add("if ({recv} == NULL) \{")
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
res = self.new_var(bool_type)
var arg = arguments[1]
if arg.mcasttype isa MNullableType then
fun send_commons(mproperty: MMethod, args: Array[Instance], mtype: MType): nullable Instance
do
if mtype isa MNullType then
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])
return self.bool_instance(args[0] == args[1])
else if mproperty.name == "!=" then
return self.bool_instance(args[0] != args[1])
#debug("recv: {recvtype} (aka {unsafe_type})")
if recvtype isa MNullType then
# `null` only accepts some methods of object.
#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'.")
unsafe_type = mmodule.object_type.as_nullable
else
self.error(node, "Error: Method '{name}' call on 'null'.")