Interface inheritance problem
Monkey Forums/Monkey Programming/Interface inheritance problem
| ||
| Hi guys, I'm having a hard time figuring out why the following code isn't working. I have a base class which implements an interface, and a child class which extends the base class and implements its own interface. I need the interface implemented by the child class to extend the one implemented by the base class and use interfaces for variable types, but I can't manage to make it work.
Interface IFoo
Method GetName:String()
End
Interface IBar Extends IFoo
Method SetName(name:String)
End
Class Foo Implements IFoo
Method GetName:String()
Return name
End
Private Field name:String = "John Doe"
End
Class Bar Extends Foo Implements IBar
' without implementing this, the code doesn't work
' Method GetName:String()
' Return name
' End
Method SetName(name:String)
Self.name = name
End
End
Function Main()
Local foo:IBar = New Bar()
foo.SetName("Mister X")
Print foo.GetName()
End
I get the following error: "Method IFoo.GetName:String() must be implemented by class Bar". It looks like Bar is not extending Foo properly. |
| ||
| What version of Monkey are you using and it looks like a bug. If you're using the latest experimental version and this fails, then report it. Edit: A workaround for now would be Class Bar Extends Foo Implements IBar
' without implementing this, the code doesn't work
Method GetName:String()
Return Super.GetName()
End
Method SetName(name:String)
Self.name = name
End
End |
| ||
| What version of Monkey are you using I'm using Monkey v77A and TRANS monkey compiler V1.39 The workaround is the same I found, but it's useless as it doesn't make sense to inherit from a base class if I have to rewrite each method every time for each subclass :( |
| ||
| The way I see it right now is that the interface is inheriting a method that needs to be implemented by the class. It doesn't consider the extended class to have the method that the interface inherited, so it's failing. A little confusing sounding, but it makes sense why this bug would occur at least. Definitely report this bug ASAP if someone hasn't already reported it. By the way, I just tried it in 78a and it failed. |
| ||
| Thank you for your prompt support. I submitted a bug report, I hope it's something which can be fixed or solved somehow. Meanwhile it would be great if someone could try this code with another monkey version. |
| ||
| This is essentially the same bug I reported last year: http://monkey-x.com/Community/posts.php?topic=6160 Mark's official response was "I can fix it, but not yet". |
| ||
| As I posted in the bug report thread, the issue was reported back in mid 2012 and got a "not right now" reply. This worse (because it's not flagged by Monkey) bug: http://www.monkeycoder.co.nz/Community/posts.php?topic=2878, in the same area, was reported around the same time, never even got a response, and appears to be still broken in 77d. I wouldn't hold your breath. |
| ||
| Perhaps a nice person could fork trans on Github and fix it. I'd do it but it'd just be another excuse to not work on my game. |