Closed swoolcock closed 2 years ago
Not all languages support this (c++, c#, Java I think) - have you actually tried it with all target languages?
On Wed, Aug 5, 2015 at 5:23 PM, Samah notifications@github.com wrote:
Monkey does not allow inherited methods to be considered when checking if a class implements all required methods of an interface. This change allows you to do that.
Interface Foo Method Hello:Void() End
Class One Method Hello:Void() Print "test" End End
Class Two Extends One Implements Foo End
Function Main() Local f:Foo = New Two f.Hello() End
Normally it would complain that Two does not implement Hello, even though
it is inherited from One.
You can view, comment on, or merge this pull request online at:
https://github.com/blitz-research/monkey/pull/81 Commit Summary
- Allows inherited methods to satisfy interface requirements.
File Changes
- M modules/trans/decl.monkey https://github.com/blitz-research/monkey/pull/81/files#diff-0 (19)
Patch Links:
- https://github.com/blitz-research/monkey/pull/81.patch
- https://github.com/blitz-research/monkey/pull/81.diff
— Reply to this email directly or view it on GitHub https://github.com/blitz-research/monkey/pull/81.
I tried it with HTML5 and cpptool, because I assumed it was an internal code generation thing. If not, is it possible to generate a pseudo-method that will just call the super version? It seems very silly to have to do that manually. My use case is that I have an abstract class implementing an interface, then a subclass implementing a subinterface. It wants me to redefine the parent interface methods in the subclass.
Edit (example):
Interface IAsset
Method Name:String() Property
End
Interface IImageAsset Extends IAsset
Method RawImage:Image() Property
End
Class Asset Implements IAsset Abstract
Field name:String
Method Name:String() Property
Return name
End
End
Class ImageAsset Extends Asset Implements IImageAsset
Field img:Image
Method RawImage:Image() Property
Return img
End
' wants me to reimplement Name
End
+1
This is the silliest thing I’ve ever seen. I have to redefine all the base GUI element methods every time I add a new element, and when something changes on the base element I have to change all the other subclasses as well. Since to have this functionality we have to write stub methods anyway, it should be something the preprocessor does for us automatically! And of course for those languages that support it, do it the good way.
Pleaaaaaaaaaase!
On Wed, Aug 5, 2015 at 7:39 AM, Samah notifications@github.com wrote:
I tried it with HTML5 and cpptool, because I assumed it was an internal code generation thing. If not, is it possible to generate a pseudo-method that will just call the super version? It seems very silly to have to do that manually. My use case is that I have an abstract class implementing an interface, then a subclass implementing a subinterface. It wants me to redefine the parent interface methods in the subclass.
— Reply to this email directly or view it on GitHub https://github.com/blitz-research/monkey/pull/81#issuecomment-127866826.
Ok, just committed a potential fix for this.
It wont fix Shane's code above, but it does/should fix stuff like this:
Interface I1
Method F1()
End
Interface I2 Extends I1
Method F2()
End
Class C Implements I1
Method F1()
Print "C.F1"
End
End
Class D Extends C Implements I2
Method F2()
Print "D.F2"
End
End
Previously, you had to add an F1() method to D for this to work.
Dunno if this is exactly what you guys are after, but IMO it's the 'right' fix. You can add whatever you want to I1 and only have to implement it in C now, instead of C and all derived classes.
You still can't do what Shane's code attempts to do, but I think with this fix that's less of an issue?
Haven't tested it too thoroughly either...!
Thanks Mark, that should fix the main issue I'm having.
This is it! I was able to remove all the stub methods from the inheriting classes, and adding a new method to the base class doesn’t force you to repeat that method on the subclasses anymore! FINALLY!
Will test more, but so far so good. Why hasn’t this been fixed before if it was so easy to implement? :/
Now there’s just that nasty bug left where called methods don’t get compiled and result in a runtime error...
On Wed, Aug 5, 2015 at 10:12 AM, Samah notifications@github.com wrote:
Thanks Mark, that should fix the main issue I'm having.
— Reply to this email directly or view it on GitHub https://github.com/blitz-research/monkey/pull/81#issuecomment-127908963.
Monkey does not allow inherited methods to be considered when checking if a class implements all required methods of an interface. This change allows you to do that.
Normally it would complain that Two does not implement Hello, even though it is inherited from One.