1
0
forked from aniani/vim

patch 9.0.1108: type error when using "any" type and adding to float

Problem:    Type error when using "any" type and adding a number to a float.
Solution:   Accept both a number and a float. (closes #11753)
This commit is contained in:
Bram Moolenaar
2022-12-29 20:56:24 +00:00
parent 73ade49c4b
commit c6951a76a5
12 changed files with 117 additions and 54 deletions

View File

@@ -2033,6 +2033,34 @@ def Test_expr8()
v9.CheckScriptFailure(['vim9script', "var x = <number>"], 'E15:', 2)
v9.CheckDefAndScriptFailure(["var x = <number >123"], 'E1068:', 1)
v9.CheckDefAndScriptFailure(["var x = <number 123"], 'E1104:', 1)
lines =<< trim END
vim9script
def Sum(v: any): float
var sum = 0.0
sum += v
return sum
enddef
const kk = 1
echo Sum(kk)
END
v9.CheckScriptSuccess(lines)
lines =<< trim END
vim9script
def Sum(v: any): float
var sum = 0.0
sum += <float>v
return sum
enddef
const kk = 1
Sum(kk)
END
v9.CheckScriptFailure(lines, 'E1012: Type mismatch; expected float but got number')
enddef
" test low level expression