Consider this somewhat contrived code:
vim9script def Foo(Parser: func(dict<any>): dict<any>): func(dict<any>): dict<any> return (ast: dict<any>): dict<any> => { return Parser(ast) } enddef var Expr: func(dict<any>): dict<any> const Call = Foo(Expr)
When sourced, it results in:
E1013: Argument 1: type mismatch, expected func(dict<any>): dict<any> but got func(): any
I would expect the code to compile, not a typing error.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications on the go with GitHub Mobile for iOS or Android.
Maybe I have wrong expectations about the laziness of the evaluation. It seems that the definition of Expr()
is bound at the time Foo()
is invoked, and not, as I thought, at the time Call()
is invoked.
Thus giving an error for unknown type looks like the best solution.
Then why not giving the same error in compiled code?
vim9script def Foo(Parser: func(dict<any>): dict<any>): func(dict<any>): dict<any> return (ast: dict<any>): dict<any> => { return Parser(ast) } enddef var Expr: func(dict<any>): dict<any>
def Func() const Call = Foo(Expr) enddef Func()
It's the exact same code. The only difference comes from Foo(Expr)
which is run from a :def
function, instead of being at the script level.
—