fix: Return original t in find_module
if search_for_token
fails
#396
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.
Fixes #258.
The if block starting at line 400 in ldoc/parse.lua is the problem.
It seems to look for a
module()
call, and then:This means that in all modern Lua code it will infer the name, obviously.
The issue is that in line 402, it calls
lang:find_module(tok, t, v)
(that isLua:find_module
fromlang.lua
), which will (for anything that doesn't usemodule()
) returnnil, t, v
wheret, v
is fromself:search_for_token(tok, 'iden', 'module', t, v)
.I know this is a bit to read, but here I believe the issue lies:
Lang:search_for_token(...)
will returnt
as nil, here's why:(from
search_for_token
)And
find_module
says:We go back to
parse.lua
, line 402:at this point
module_found
would be nil, andt
would be nil also.Now, a few lines down:
So this is the issue -
t
may VERY well be nil.Alternatively, we could:
break
need to be there, so I will not remove it.break
only, and hope nothing relies on this - again, not sure that's the right move.t
arbitrarily being set tonil
seems wrong here, so that's what I fixed, and it fixes the issue with the following reproducible sample:And also seems to work fine for code using
module()
.