Ernie Rael wrote:
> I saw some recent msgs about comparing anything to null, and that it > would be allowed. I guess I got the wrong impression. Using vim: > "Included patches: 1-4507" > > In my first vim9 script, I did (the real code conditionally return null) > > def Get(): string > return null > enddef > > And this doesn't compile because "Type mismatch; expected string but got > special". > > Allowing null seems like an improvement. I am still looking into how we should use null. In many places null is handled the same as an empty string. In this example you might as well return an empty string, since it will be the same for most purposes. There are also complications, such as when assigning null to a variable, when getting that value it looks like the variable wasn't initialized, so it will be initialzed then and when it is a list, get an empty list instead of null. That might be confusing. Also, a null list cannot store a type, because the type is kept on the list. Not sure if this matters, since this only matters for declared variables, which, as just mentioned, are initialized to an empty list/dict/etc., and then the type is added. > In my case, I can do "def Get(): any", but then there's a runtime checking. That is not a good solution, any reason you can't return an empty string? > Would allowing it to be null incur some additional runtime check? The > following fails at runtime, so that can't be it entirely: > > var xxx = 'foo' > xxx = 'bar' > xxx = null > > I guess how to handle a "null string" might be part of the issue. In my > case, when the value is null, it only gets used in a comparison. That's what was implemented so far, comparing with null. -- "Hit any key to continue" is a lie. /// Bram Moolenaar -- [email protected] -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org /// -- -- You received this message from the "vim_dev" maillist. Do not top-post! Type your reply below the text you are replying to. For more information, visit http://www.vim.org/maillist.php --- You received this message because you are subscribed to the Google Groups "vim_dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/vim_dev/20220305104820.E30B11C1A81%40moolenaar.net.
