[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 583: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/session.php on line 639: sizeof(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/postgres.php on line 286: pg_fetch_assoc(): supplied resource is not a valid PostgreSQL result resource
[phpBB Debug] PHP Warning: in file [ROOT]/phpbb/db/driver/postgres.php on line 286: pg_fetch_assoc(): supplied resource is not a valid PostgreSQL result resource
Project Epsylon •null types
Page 1 of 1

null types

Posted: Sat Sep 18, 2004 3:14 pm
by Khan
I don't know what the offficial stand on this is, so it doesn't get a [Bug]-Tag.

Basically null is of any type, which allows you to call any method with null without any static Type.
The question is what to do if you have overloaded methods. The Java way is to choose the most specific one, if there is none, we get a compiler errror. DragonScript at the current state always generates a compiler error.
I can see arguments for both ways, I just wanted to make sure, the current behaviour is wanted and not coincidence.

lets first say we have to following Code to call the method

Code: Select all

	func void testNull1()
		var NullTest1 test = NullTest1.new()
		test.sampleFunc(null)
	end
The following would work in Java but not DragonScript

Code: Select all

class NullTest1
	func new()
	end
	
	func void sampleFunc(object o)
		System.print("sampleFunc(object)\n")
	end
	
	func void sampleFunc(String s)
		System.print("sampleFunc(String)\n")
	end
end
The method with the String as argument would be invoked.

This code must never compile (and doesn't):

Code: Select all

class NullTest1
	func new()
	end
	
	func void sampleFunc(object o)
		System.print("sampleFunc(object)\n")
	end
	
	func void sampleFunc(String s)
		System.print("sampleFunc(String)\n")
	end

	func void sampleFunc(NullTest1 n)
		System.print("sampleFunc(NullTest1)")
	end
end

Posted: Sat Sep 18, 2004 4:21 pm
by Dragonlord
so far this is what i wanted. i've come across this problem implementing the type system. in the case mentioned the parser has to decide what it does with the null object in a case where there are no direct-matching functions (direct matching means the types match 1-1, partially matching means you can achiece a match by down-casting certain arguments). so what do we want to do?
1) test.sampleFunc(null cast object)
2) test.sampleFunc(null cast string)

here we've got two facilities colliding. one facility would only look for down-castability, which in fact only can be achieved with the first version (null is of class 'null' with base class 'object'). now the second facility allows an object of type 'null' to be auto-casted to any other type. and now we've got two partial-matching functions and a situation the parser can no more decide which function he should call.

to solve that problem i decided to utter out an error because such a call is tricky and can quickly end in a wrong function called. that's what i came up with but perhaps you see a better way to deal with this peculiar situation.