Interface member not declared, why no error?

Monkey Forums/Monkey Beginners/Interface member not declared, why no error?

Hero(Posted 2015) [#1]
OK,

I am sorry for spamming the forums right now but to me the monkey-x language behaves a bit unexpected for me in many ways.

The language reference sais:

Classes that implement an interface must declare each method declared in the interface.


This does not seem to be enforced. The following code will compile just fine with no error:

Strict

Import mojo2

Interface IRenderable
	
	Method RenderTarget:Canvas() Property

End


Strict

Import mojo2
Import irenderable

Class iPlayfield Implements IRenderable
	
	Private
	Field renderTarget:Canvas
	
	Public
	#Rem
	Method RenderTarget:Canvas() Property
		Return renderTarget
	End
	#End
End


My expectation was that this should generate an error because the Class iPlayfeld does not implement the RenderTarget Property Method of IRenderable.


bitJericho(Posted 2015) [#2]
I can confirm this looks like a bug to me with the following similar example:

Strict


Function Main:Int()
	New test()
	Return 0
End

Class test Implements ITest
	
	Method New()
		Print "test"
	End
	

End

Interface ITest

	Method MTest:Void()
    
End



therevills(Posted 2015) [#3]
Monkey's compiler is a bit strange, it'll only compile methods/functions/classes which are actually used. To get around it add #REFLECTION_FILTER="*" to the top of your code, this will force Monkey to compile all code (once you are happy with your code and you dont plan on using reflection just remove it).


ImmutableOctet(SKNG)(Posted 2015) [#4]
Don't force the reflection filter to everything, that will be monstrously slow. Just add things you want to check. Errors unresolved by the compiler aren't going to effect your code anyway, as they aren't used anywhere. This means if you don't use your 'RenderTarget' property, there's no need to require it. There's flaws with this system, but ultimately, you're getting quite a few benefits from this. For more information on reflection, click here. Also see this thread, regarding the same topic.


bitJericho(Posted 2015) [#5]
I think even if its unused monkey should check for interface problems. In my mind it seems like a syntax error and like it's an omission, but I understand it doesn't actually cause problems until you try to use it.