[vim/vim] Interfaces should not support class methods and variables (PR #13100)

21 views
Skip to first unread message

Yegappan Lakshmanan

unread,
Sep 16, 2023, 2:49:52 AM9/16/23
to vim/vim, Subscribed

Vim9 interface changes to follow the new interface specification:

  1. An interface can have only read-only and read-write instance variables.
  2. An interface can have only public instance methods.
  3. An interface cannot have class variables and class methods.
  4. An interface cannot have private instance variables and private instance methods.
  5. A interface can extend another interface using "extends". The sub-interface gets all the variables and methods in the super interface.

You can view, comment on, or merge this pull request online at:

  https://github.com/vim/vim/pull/13100

Commit Summary

  • fe2a991 Interfaces should not support class methods and variables

File Changes

(3 files)

Patch Links:


Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 2:59:50 AM9/16/23
to vim/vim, Push

@yegappan pushed 1 commit.


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/push/15064883879@github.com>

codecov[bot]

unread,
Sep 16, 2023, 3:14:57 AM9/16/23
to vim/vim, Subscribed

Codecov Report

Merging #13100 (a8b7628) into master (ffb1367) will decrease coverage by 1.60%.
The diff coverage is 96.42%.

@@            Coverage Diff             @@
##           master   #13100      +/-   ##
==========================================
- Coverage   78.26%   76.66%   -1.60%     
==========================================
  Files         150      150              
  Lines      152693   152425     -268     
  Branches    39364    39287      -77     
==========================================
- Hits       119508   116861    -2647     
- Misses      20935    23532    +2597     
+ Partials    12250    12032     -218     
Flag Coverage Δ
mingw-x64-HUGE 76.66% <96.42%> (-0.02%) ⬇️
mingw-x86-HUGE ?
windows 76.66% <96.42%> (-1.60%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/vim9class.c 87.81% <96.42%> (-0.38%) ⬇️

... and 86 files with indirect coverage changes


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/c1722160568@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 11:02:34 AM9/16/23
to vim/vim, Push

@yegappan pushed 1 commit.

  • e1774d6 Interfaces should not support class methods and variables

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/push/15067134247@github.com>

errael

unread,
Sep 16, 2023, 11:47:40 AM9/16/23
to vim/vim, Subscribed

@errael commented on this pull request.


In src/errors.h:

>  	INIT(= N_("E1377: Static member is not supported in an interface"));
 EXTERN char e_method_str_of_class_str_has_different_access[]
 	INIT(= N_("E1378: Access level of method \"%s\" is different in class \"%s\""));
+EXTERN char e_static_cannot_be_used_in_interface[]
+	INIT(= N_("E1379: Static cannot be used in an interface"));

E1377 is not used. Looks E1379 has taken it's place.


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/review/1629978741@github.com>

errael

unread,
Sep 16, 2023, 12:55:58 PM9/16/23
to vim/vim, Subscribed

In the following class B satisfies the I2 contract since F1 is inherited from class A. Doesn't seem like should be an error. An equivalent Java program compiles fine.

E1349: Function "F1" of interface "I2" not implemented
vim9script

interface I2
    def F1()
    def F2()
endinterface

class A
    def F1()
    enddef
endclass

class B extends A implements I2
    def F2()
    enddef
endclass


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/c1722270087@github.com>

errael

unread,
Sep 16, 2023, 1:26:21 PM9/16/23
to vim/vim, Subscribed

This seems like it should work. Gets

E1315: White space required after name: I1, I2
vim9script

interface I1
    def F1()
    def F2()
endinterface

interface I2
    def F2()
    def F3()
endinterface

interface I3 extends I1, I2
endinterface

class C implements I3
    def F1()
    enddef
    def F2()
    enddef
    def F3()
    enddef
endclass


Reply to this email directly, view it on GitHub.

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/c1722276538@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 1:49:53 PM9/16/23
to vim/vim, Push

@yegappan pushed 1 commit.

  • e77dd95 Adjust error numbers and add additional tests

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/push/15067947039@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 1:50:10 PM9/16/23
to vim/vim, Push

@yegappan pushed 2 commits.

  • e0bd542 Interfaces should not support class methods and variables
  • 8d8018f Adjust error numbers and add additional tests

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/push/15067948255@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 1:55:33 PM9/16/23
to vim...@googlegroups.com, reply+ACY5DGAL32EA366X3V...@reply.github.com, vim/vim, Subscribed
Hi,

On Sat, Sep 16, 2023 at 10:26 AM errael <vim-dev...@256bit.org> wrote:

This seems like it should work. Gets

E1315: White space required after name: I1, I2
vim9script

interface I1
    def F1()
    def F2()
endinterface

interface I2
    def F2()
    def F3()
endinterface

interface I3 extends I1, I2

Currently only one interface or class name can be specified after "extends" (an interface can extend
only one interface).

Regards,
Yegappan

vim-dev ML

unread,
Sep 16, 2023, 1:55:52 PM9/16/23
to vim/vim, vim-dev ML, Your activity

Hi,


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/c1722282327@github.com>

errael

unread,
Sep 16, 2023, 2:38:00 PM9/16/23
to vim/vim, vim-dev ML, Comment

Currently only one interface or class name can be specified after "extends"

"Currently" as in squeeze it in or possible post vim9.1 thing. There are straightforward workarounds, as seen in the example below. But there's an issue as shown in the next message

vim9script

interface I1
    def F1()
    def F2()
endinterface

interface I2 extends I1
    def F2()
    def F3()
endinterface

# want "extends I1, I2", so manually add I2's stuff to I3
interface I3 extends I1
    def F2()
    def F3()
endinterface

# and manually add I2 to class C
class C implements I3, I2
    def F1()
    enddef
    def F2()
    enddef
    def F3()
    enddef
endclass

def F1(i: I1)
enddef

def F2(i: I2)
enddef

def F3(i: I3)
enddef

var oc = C.new()
F1(oc)
F2(oc)
F3(oc)


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/c1722290177@github.com>

errael

unread,
Sep 16, 2023, 2:40:38 PM9/16/23
to vim/vim, vim-dev ML, Comment

Looks like an inherited interface is not getting picked up by a class

E1013: Argument 1: type mismatch, expected object<I1> but got object<C>
vim9script

interface I1
    def F1()
endinterface

interface I2 extends I1
    def F2()
endinterface

class C implements I2
    def F1()
    enddef
    def F2()
    enddef
endclass

def F1(i: I1)
enddef

var oc = C.new()
F1(oc)


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/c1722290651@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 4:35:51 PM9/16/23
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • a26fbae Interface methods can be defined in one of the super classes

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/push/15068676587@github.com>

errael

unread,
Sep 16, 2023, 5:59:37 PM9/16/23
to vim/vim, vim-dev ML, Comment

Member can not be repeated in subinterface (but function can)

E1369: Duplicate member: rval
vim9script

interface I1
    this.rval: string
endinterface

interface I2 extends I1
    this.rval: string
endinterface

But this works

vim9script

interface I1
    def F1()
endinterface

interface I2 extends I1
    def F1()
endinterface


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/c1722324860@github.com>

errael

unread,
Sep 16, 2023, 6:15:01 PM9/16/23
to vim/vim, vim-dev ML, Comment

(Similar to #13100 (comment) but with members.)

In the following class B satisfies the I2 contract since rval1 is inherited from class A.

E1348: Member "rval1" of interface "I2" not implemented
vim9script

interface I2
    this.rval1: number
    this.rval2: number
endinterface

class A
    this.rval1: number
endclass

class B extends A implements I2
    this.rval2: number
endclass


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/c1722327961@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 8:49:32 PM9/16/23
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • 8e68a4e Interface variables can be defined in one of the super classes. Instance variables can be repeated in sub interfaces

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/push/15069627363@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 9:00:58 PM9/16/23
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • 3e6e629 Remove trailing whitespace

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/push/15069675735@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 9:25:13 PM9/16/23
to vim/vim, vim-dev ML, Comment

@yegappan commented on this pull request.


In src/errors.h:

>  	INIT(= N_("E1377: Static member is not supported in an interface"));
 EXTERN char e_method_str_of_class_str_has_different_access[]
 	INIT(= N_("E1378: Access level of method \"%s\" is different in class \"%s\""));
+EXTERN char e_static_cannot_be_used_in_interface[]
+	INIT(= N_("E1379: Static cannot be used in an interface"));

I have used E1377 for some other message.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/review/1630028314@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 9:26:40 PM9/16/23
to vim/vim, vim-dev ML, Comment

Member can not be repeated in subinterface (but function can)

I have updated the PR to address this.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/c1722361108@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 9:27:06 PM9/16/23
to vim/vim, vim-dev ML, Comment

(Similar to #13100 (comment) but with members.)

In the following class B satisfies the I2 contract since rval1 is inherited from class A.

E1348: Member "rval1" of interface "I2" not implemented

I have updated the PR to address this.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/c1722361196@github.com>

Yegappan Lakshmanan

unread,
Sep 16, 2023, 9:27:46 PM9/16/23
to vim/vim, vim-dev ML, Comment

Looks like an inherited interface is not getting picked up by a class

E1013: Argument 1: type mismatch, expected object<I1> but got object<C>

This should be addressed in the updated PR.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/c1722361362@github.com>

errael

unread,
Sep 16, 2023, 9:50:32 PM9/16/23
to vim/vim, vim-dev ML, Comment

Missing interface variable type checking.

This executes with no error. Expect compilation errors. And I hope you get at least a chuckle over the behavior described in the comment to class C ...

vim9script

interface I1
    public this.rval: number
endinterface

# this should produce a type mismatch error
interface I2 extends I1
    public this.rval: string
endinterface

# I've never been entirely clear on when/if a variable gets a type,
# but in the following, if rval is not given a type, it is "any".
#
# If it is typed number it complains about wanting string, and vice versa.
#
class C implements I2
    #public this.rval: list<string> = [ "init-rval" ]
    #public this.rval: string
    #public this.rval: number
    public this.rval = [ "init-rval" ]
endclass

var oc = C.new()
echo "oc.rval:" oc.rval
oc.rval = "xxx"
echo "oc.rval:" oc.rval


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/c1722366262@github.com>

Yegappan Lakshmanan

unread,
Sep 17, 2023, 12:29:18 AM9/17/23
to vim/vim, vim-dev ML, Push

@yegappan pushed 1 commit.

  • 11d6e2c Check the class variable types with the type in interface

You are receiving this because you are subscribed to this thread.Message ID: <vim/vim/pull/13100/push/15070393620@github.com>

Yegappan Lakshmanan

unread,
Sep 17, 2023, 12:48:14 AM9/17/23
to vim/vim, vim-dev ML, Comment

Missing interface variable type checking.

I have updated the PR with a fix for this.

This executes with no error. Expect compilation errors. And I hope you get at least a chuckle over the behavior described in the comment to class C ...

Yes. I have added a fix for this issue also in the PR.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/c1722391172@github.com>

errael

unread,
Sep 17, 2023, 1:36:16 AM9/17/23
to vim/vim, vim-dev ML, Comment

Looks good and ready for wider use. Maybe I'll think of something extremely obscure tomorrow, but maybe not.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/c1722397823@github.com>

Christian Brabandt

unread,
Sep 17, 2023, 11:07:23 AM9/17/23
to vim/vim, vim-dev ML, Comment

Closed #13100 via 92d9ee5.


Reply to this email directly, view it on GitHub.

You are receiving this because you commented.Message ID: <vim/vim/pull/13100/issue_event/10391526463@github.com>

Reply all
Reply to author
Forward
0 new messages