Improve generic pattern to support optional, union, array. Fixed regression. #3031
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I examined the original generic pattern code in more detail and realized that it incorrectly handles cases when it cannot parse further. We need to partially successfully parse, not cancel it by
return nil
.T
.*-" #3015 whereparseCode
was replaced withparseCodePattern
The signs
<>
are also correctly recognized, but the generics don't support it at all.My complete test
I'm checking the
protoNode (self.proto)
ingeneric:resolve
. This node is created inserver\script\vm\compiler.lua:1753
in: case 'function.return'
wherertn (proto)
has optional butvm.createGeneric
is not.lua-language-server/script/vm/compiler.lua
Lines 1751 to 1756 in cb964c6
Well, I think
generic:resolve
is the best place.lua-language-server/script/vm/generic.lua
Lines 139 to 142 in 5f0efc4
But there is some change here. Previously the optional unresolved generic was
unknown
, but now it chooses betweenunknown|nil
so becomesnil
I think its OK, otherwise its different issue.
Minor changes
m.R('__')
fromname
parsing because it the same asm.S('_')
, so nothing changed.next
variable tonextTp
to avoid names conflict.boolean
peek, not a string'peek'
.