0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)

Problem:    Vim9: no type error if assigning a value with type func(number) to
            a variable of type func(string).
Solution:   Use check_type_maybe(): return MAYBE if a runtime type check is
            useful.  (issue #8492)
This commit is contained in:
Bram Moolenaar
2021-12-18 12:31:33 +00:00
parent 647ab4cede
commit 44a8977de4
5 changed files with 69 additions and 9 deletions

View File

@@ -2146,6 +2146,23 @@ def Test_script_funcref_case()
CheckScriptFailure(lines, 'E704:')
enddef
def Test_script_funcref_runtime_type_check()
var lines =<< trim END
vim9script
def FuncWithNumberArg(n: number)
enddef
def Test()
var Ref: func(string) = function(FuncWithNumberArg)
enddef
defcompile
END
# OK at compile time
CheckScriptSuccess(lines)
# Type check fails at runtime
CheckScriptFailure(lines + ['Test()'], 'E1012: Type mismatch; expected func(string) but got func(number)')
enddef
def Test_inc_dec()
var lines =<< trim END
var nr = 7