vim9 icon indicating copy to clipboard operation
vim9 copied to clipboard

Fix measurement code causes E1017 and type mismatch

Open rhysd opened this issue 6 years ago • 1 comments

Hi,

thank you for exciting new-year present! I tried the measurement code in README.md on my local and noticed it caused an error as follows:

E1017: Variable already declared: sum

Though I'm not fully understanding the grammar, it seems that let is used for declaration in new syntax. is_decl is set to true on :let or :const so I guess assignment to existing variable should be in var = expr style.

https://github.com/brammool/vim9/blob/f9a84f6e12b633006b0bbc82101dee2c994c478e/src/vim9compile.c#L2747

After this fix above E1017 no longer occurred.

rhysd avatar Jan 03 '20 03:01 rhysd

I also found that the measurement code still caused a type error because return type was not set to VimNew.

It seems that function return type is void by default here if type annotation is missing:

https://github.com/brammool/vim9/blob/f9a84f6e12b633006b0bbc82101dee2c994c478e/src/userfunc.c#L2862

And VimNew returns number so its return type must be typed. After this fix, I confirmed the measurement code runs correctly. And vim9 is far faster! :+1:

4499998500000
Vim old:   6.321314
4499998500000
Vim new:   0.138511

rhysd avatar Jan 03 '20 03:01 rhysd