summaryrefslogtreecommitdiff
path: root/src/testdir/test_vim9_assign.vim
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2021-12-18 12:31:33 +0000
committerBram Moolenaar <Bram@vim.org>2021-12-18 12:31:33 +0000
commit44a8977de467241a2f9959253d06eff53a8baad9 (patch)
tree4ec6b318b1235e40aaf2fc7989142b0e4a7edca5 /src/testdir/test_vim9_assign.vim
parent647ab4cede4dbf412d24748f8e0a64d1cb9239f4 (diff)
downloadvim-git-44a8977de467241a2f9959253d06eff53a8baad9.tar.gz
patch 8.2.3844: Vim9: no type error if assigning func(number) to func(string)v8.2.3844
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)
Diffstat (limited to 'src/testdir/test_vim9_assign.vim')
-rw-r--r--src/testdir/test_vim9_assign.vim17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/testdir/test_vim9_assign.vim b/src/testdir/test_vim9_assign.vim
index e1fe09578..f7af299e4 100644
--- a/src/testdir/test_vim9_assign.vim
+++ b/src/testdir/test_vim9_assign.vim
@@ -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