1
0
forked from aniani/vim

patch 8.2.3869: Vim9: type checking for "any" is inconsistent

Problem:    Vim9: type checking for "any" is inconsistent.
Solution:   Always use a runtime type check for using "any" for a more
            specific type.
This commit is contained in:
Bram Moolenaar
2021-12-22 13:18:39 +00:00
parent 1b5f7a6202
commit fa46ead31a
5 changed files with 35 additions and 26 deletions

View File

@@ -548,7 +548,7 @@ def Test_call_default_args()
END
CheckScriptFailure(lines, 'E1001: Variable not found: b')
# using script variable requires matching type or type cast
# using script variable requires matching type or type cast when executed
lines =<< trim END
vim9script
var a: any
@@ -557,18 +557,8 @@ def Test_call_default_args()
enddef
defcompile
END
CheckScriptFailure(lines, 'E1013: Argument 1: type mismatch, expected string but got any')
lines =<< trim END
vim9script
var a: any
def Func(arg: string = <string>a)
echo arg
enddef
a = 'works'
Func()
END
CheckScriptSuccess(lines)
CheckScriptSuccess(lines + ['a = "text"', 'Func()'])
CheckScriptFailure(lines + ['a = 123', 'Func()'], 'E1013: Argument 1: type mismatch, expected string but got number')
# using global variable does not require type cast
lines =<< trim END