fix: correct malformed type() checks (C7)#40
Merged
Conversation
aldum
approved these changes
Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Five type() guards across the codebase share one defect shape — the comparison ends up inside the type() call, or
notbinds to type() before the comparison — so the guard never does its job:table.is_array,table.flatten,table.odds(util/table.lua):not type(self) == "table"is always false, so the check reduces tonot self, and passing any non-table scalar crashes onpairsinstead of returning false/nil. These are reachable throughanalyze.luaanddebug.lua.2
UserInputModel:set_error:type(errors[1] == "string")istype(boolean), always truthy, so the branch that converts non-string errors withtostringis dead and raw error tables are stored in a field annotatedstring[]. The display path happens totostringelements anyway, which masks it today, but any other consumer of the field gets tables where strings are promised.is_lua_block(md/parser.lua):not type(t) == "table"never returns early; strings survive by accident (string indexing doesn't raise), other scalars would.All five become the intended
type(x) ~= "table"/type(x) == "string"forms.The same pattern exists once more in the stringutils submodule (string.lua:241) — out of scope here, can be fixed upstream separately.