lua-language-server
lua-language-server copied to clipboard
Allow type `T1?|T2?`
T1?|T2? is now parsed as T1?, whose correct form should be (T1|T2)? or T1|T2|nil or field? T1|T2.
But many libraries (e.g. neovim plugins) are using this incorrect form.
This misuse is so prevalent that should we consider making this form legal?
If there are too many errors, they should be supported, then we would have to support too many cases. Why not let others fix the errors instead?
If we support this feature of yours, the type expression will become ambiguous.
T1|T2?, will be parsed as (T1 | T2)? or T1|(T2?)
If there are too many errors, they should be supported, then we would have to support too many cases.
I respect your argument and effort as a maintainer. But I think this misuse is not entirely groundless.
Currently T1|T2? and T1|nil|T2|nil(maybe unintentionally) are both accepted and mean the same. And according this comment,
in luals ? is also shorthand for marking the type as |nil
then T1?|T2? is a natural expansion of ? -> |nil to T1|nil|T2|nil.
T1?|T2 now is just T1?. I guess the parsing just stops after finding a ?.
T1|T2?, will be parsed as(T1 | T2)?orT1|(T2?)
As for ambiguity, syntactically ? should have the most precedence as a unary operator, thus the above should mean T1|(T2?). Semantically these two are identical, so as long as one type in a | list has a ? the final type has |nil.
I'm not requesting this feature, just offering some suggestions for your consideration. Again, I respect your decisions as maintainers.
My comments are not important and usually only represent my personal opinions. They will not influence the decisions of this project. I am not truly maintaining this project; I have my own projects to maintain. Based on the current state of maintenance, unless someone submits a PR to support it, nothing will change.