Shadowing in Monkey

Monkey Forums/Monkey Programming/Shadowing in Monkey

ziggy(Posted 2012) [#1]
don't you think shadowing should be treatened as an error in the compiler?
Function Main()
	Local another:Another
	another.SomeFunc()  'I know it should not be called using an instance, it's just an example.
	Local myclass:MyClass = MyClass(another)
	myclass.SomeFunc()
End

Class MyClass
	Function SomeFunc:Int()
		Print "One"
	End
End

Class Another extends MyClass 
	Function SomeFunc:Int()
		Print "Two"
	End
End

One may think that the static fucntion SomeFunc is being overriden in the extension class, but it is not, they're separated functions and you can call one or the other just with simple downcasting. The same happens with Fields that have the same name in the inheritance chain, but in this case, it's properly handled by the compiler. Obviously, as functions in classes do not require a instance (and should not be called this way IMHO) this is not really an issue, I'm just surprised that the compiler allows this. don't know if it makes any sense tho...