Vim 9 script allows the following definitions, in which I2 extends I1 by
"implementing" it:
interface I1
def Foo()
endinterface
interface I2 implements I1
def Foo()
def Bar()
endinterface
The above compiles: I don't know whether it is intentional, but it is
pretty cool! Or, it would be if the following code worked:
def Echo(obj: I1)
obj.Foo()
enddef
class C2 implements I2
def Foo()
echo 'C2'
enddef
def Bar()
enddef
endclass
const c2 = C2.new()
Echo(c2) # ERROR
This results in:
type mismatch, expected object<I1> but got object<C2>
But C2 does conform to I1! To fix the error, it is necessary to declare
all the interfaces implemented by C2, that is:
class C2 implements I1, I2
# etc.
I will mention two other minor issues:
- I2 must declare Foo() again: it would be nice if that definition could
be inferred.
- "implements" is not a very accurate description: "extends" would make
more sense, intuitively.
In summary, what I am asking is whether Vim could (or should) support
this syntax:
interface I1
def Foo()
endinterface
interface I2 extends I1
def Bar()
endinterface
with the following implications:
1. any class implementing I2 must implement both Foo() and Bar().
2. any object of a class implementing I2 may be used wherever an object
with type I1 is expected.
Thanks,
Life.
--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/u990to%24rvl%241%40ciao.gmane.io.
No comments:
Post a Comment