mirror of
https://github.com/vim/vim.git
synced 2025-10-04 05:25:06 -04:00
patch 9.0.1741: No type checking in interfaces
Problem: No type checking in interfaces Solution: Implement member type check in vim9 interfaces Most of the code is a small refactoring to allow the use of a where_T for signaling the type mismatch, the type checking itself is pretty simple. Improve where_T error reports Let the caller explicitly define the kind of location it's referring to and free the WT_ARGUMENT enum from its catch-all role. Implement type checking for interface methods Follows closely the logic used for type-checking the members. closes: #12844 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: LemonBoy <thatlemon@gmail.com>
This commit is contained in:
committed by
Christian Brabandt
parent
56bafd7a6a
commit
c5d2744c04
@@ -1576,6 +1576,61 @@ def Test_class_implements_interface()
|
||||
endclass
|
||||
END
|
||||
v9.CheckScriptFailure(lines, 'E1349:')
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
|
||||
interface One
|
||||
static matching: bool
|
||||
static as_any: any
|
||||
static not_matching: number
|
||||
endinterface
|
||||
class Two implements One
|
||||
static not_matching: string
|
||||
static as_any: string
|
||||
static matching: bool
|
||||
endclass
|
||||
END
|
||||
v9.CheckScriptFailure(lines, 'E1406: Member "not_matching": type mismatch, expected number but got string')
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
|
||||
interface One
|
||||
def IsEven(nr: number): bool
|
||||
endinterface
|
||||
class Two implements One
|
||||
def IsEven(nr: number): string
|
||||
enddef
|
||||
endclass
|
||||
END
|
||||
v9.CheckScriptFailure(lines, 'E1407: Member "IsEven": type mismatch, expected func(number): bool but got func(number): string')
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
|
||||
interface One
|
||||
def IsEven(nr: number): bool
|
||||
endinterface
|
||||
class Two implements One
|
||||
def IsEven(nr: bool): bool
|
||||
enddef
|
||||
endclass
|
||||
END
|
||||
v9.CheckScriptFailure(lines, 'E1407: Member "IsEven": type mismatch, expected func(number): bool but got func(bool): bool')
|
||||
|
||||
lines =<< trim END
|
||||
vim9script
|
||||
|
||||
interface One
|
||||
def IsEven(nr: number): bool
|
||||
endinterface
|
||||
class Two implements One
|
||||
def IsEven(nr: number, ...extra: list<number>): bool
|
||||
enddef
|
||||
endclass
|
||||
END
|
||||
v9.CheckScriptFailure(lines, 'E1407: Member "IsEven": type mismatch, expected func(number): bool but got func(number, ...list<number>): bool')
|
||||
enddef
|
||||
|
||||
def Test_call_interface_method()
|
||||
|
Reference in New Issue
Block a user