fix(spec): correct assertion for metatable with __metatable=nil#75
Open
mcepl wants to merge 2 commits intokikito:masterfrom
Open
fix(spec): correct assertion for metatable with __metatable=nil#75mcepl wants to merge 2 commits intokikito:masterfrom
mcepl wants to merge 2 commits intokikito:masterfrom
Conversation
A test case in `spec/inspect_spec.lua` was failing when run with
LuaJIT on aarch64. The test checks the behavior of `inspect` on
tables with metatables that have the `__metatable` field set.
The failure occurred for the case where `__metatable` was set to
`nil`. The `inspect` function correctly hides the metatable in
this scenario, as `getmetatable` returns `nil`. However, the test
was expecting the metatable to be displayed, and with incorrect
content, causing the assertion to fail.
This commit corrects the failing assertion to expect the correct
output from `inspect`, which is an empty table string `'{}'`.
This aligns the test with the documented behavior of Lua's
`getmetatable` and the current implementation of the library.
Co-developed-by: Gemini gemini-2.5-pro
Signed-off-by: Matěj Cepl <mcepl@cepl.eu>
Author
|
So, this made the test suite pass with LuaJIT/aarch64, but it broke for everywhere else. Whoopsie! Gemini suggested this patch to fix it, but it doesn’t work: --- a/inspect.lua
+++ b/inspect.lua
@@ -320,12 +320,19 @@
end
local mt = getmetatable(t)
- if type(mt) == 'table' then
- if seqLen + keysLen > 0 then puts(buf, ',') end
- tabify(self)
- puts(buf, '<metatable> = ')
- self:putValue(mt)
+ if type(mt) == 'table' then
+ local protected = rawget(mt, '__metatable')
+ if protected ~= nil and type(protected) ~= 'table' then
+ mt = nil
+ end
+ end
+ if type(mt) == 'table' then
+ if seqLen + keysLen > 0 then puts(buf, ',') end
+ tabify(self)
+ puts(buf, '<metatable> = ')
+ self:putValue(mt)
end
self.level = self.level - 1 |
kikito
reviewed
Nov 3, 2025
Co-authored-by: Enrique García Cota <kikito@gmail.com>
7c97e4b to
bcc8d03
Compare
Author
|
Seems to work. Will test more. |
kikito
requested changes
Jan 5, 2026
Owner
kikito
left a comment
There was a problem hiding this comment.
Hi, thanks for the PR and sorry it took me a while to review. I think it could be simplified a bit.
Comment on lines
+30
to
+36
| -- Standardize common Unix architectures | ||
| if arch:match("^(x86_64|amd64|aarch64|arm64|mips64)") then | ||
| return arch | ||
| elseif arch:match("^(i%d86|x86|i386|arm|mips)") then | ||
| return arch | ||
| end | ||
| return arch -- Return raw uname output if not a common match |
Owner
There was a problem hiding this comment.
Isn't this just the same as
Suggested change
| -- Standardize common Unix architectures | |
| if arch:match("^(x86_64|amd64|aarch64|arm64|mips64)") then | |
| return arch | |
| elseif arch:match("^(i%d86|x86|i386|arm|mips)") then | |
| return arch | |
| end | |
| return arch -- Return raw uname output if not a common match | |
| return arch -- Return raw uname output if not a common match |
?
| local is_luajit, ffi = pcall(require, 'ffi') | ||
| local has_rawlen = type(_G.rawlen) == 'function' | ||
|
|
||
| local function get_host_architecture() |
Owner
There was a problem hiding this comment.
This might be a bit overengineered. It looks like we only need to know whether the architecture is "aarch64". None of the other values are used on any test.
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.
A test case in
spec/inspect_spec.luawas failing when run with LuaJIT on aarch64. The test checks the behavior ofinspecton tables with metatables that have the__metatablefield set.The failure occurred for the case where
__metatablewas set tonil. Theinspectfunction correctly hides the metatable in this scenario, asgetmetatablereturnsnil. However, the test was expecting the metatable to be displayed, and with incorrect content, causing the assertion to fail.This commit corrects the failing assertion to expect the correct output from
inspect, which is an empty table string'{}'. This aligns the test with the documented behavior of Lua'sgetmetatableand the current implementation of the library.Co-developed-by: Gemini gemini-2.5-pro