contravariant argument types

Found a bug in the language, the VM or the compiler? help us iron things out or give ideas for doing things better.
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
User avatar
Khan
Intermediate
Posts:69
Joined:Fri Sep 17, 2004 9:31 am
Location:src/packages/collections/
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
contravariant argument types

Post by Khan » Sat Sep 18, 2004 3:25 pm

I know this is wanted behaviour and it relevance in practice is questionable but I post it anyway (remenber, generating traffic ;) )

Type theory sez:
If we have a type T, with a method M that takes an argument of type X. Then type S is a Subtype of T if it has a method M that takes an argument of type X or a supertype of X.

Code: Select all

class T
	func new()
	end
	
	func void M(String s)
		System.print("A.M(String)\n")
	end
end

class S extends T
	func new() super()
	end

	func void M(object o)
		System.print("S.M(object)\n")
	end
end
In this case, that would mean, that M of S overrides M of T. In DragonScript right now this is not the case.

User avatar
Dragonlord
Forum Administrator
Posts:609
Joined:Fri Jul 30, 2004 4:30 pm
Location:Switzerland
Contact:

Post by Dragonlord » Sat Sep 18, 2004 4:38 pm

yep. this is wanted and i though through some examples (which even would hold a usability for that theory). but so far the possible merit isn't that blistering to justify that change. might be done once in the future perhaps but i doubt it.
Image
Oh to be a dragon, of silkworm size or immense...

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable