Skip to content

Commit 7592060

Browse files
RomanSpectorclaude
andcommitted
Address review: fix union type handling and extract helper
- value.lua: clear result when any non-integer type is found in node, preventing incorrect integer return for union types (integer|string) - operator.lua: extract getOperandInfers() helper to deduplicate URI/infer retrieval across 5 call sites Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 93b666b commit 7592060

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

script/vm/operator.lua

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ vm.OP_UNARY_MAP = util.revertMap(unaryMap)
5858
vm.OP_BINARY_MAP = util.revertMap(binaryMap)
5959
vm.OP_OTHER_MAP = util.revertMap(otherMap)
6060

61+
---@param source parser.object
62+
---@return uri, vm.infer, vm.infer
63+
local function getOperandInfers(source)
64+
return guide.getUri(source), vm.getInfer(source[1]), vm.getInfer(source[2])
65+
end
66+
6167
---@param operators parser.object[]
6268
---@param op string
6369
---@param value? parser.object
@@ -270,9 +276,7 @@ vm.binarySwitch = util.switch()
270276
return
271277
end
272278
-- Bitwise ops on integers always produce integer
273-
local uri = guide.getUri(source)
274-
local infer1 = vm.getInfer(source[1])
275-
local infer2 = vm.getInfer(source[2])
279+
local uri, infer1, infer2 = getOperandInfers(source)
276280
if infer1:hasType(uri, 'integer')
277281
and infer2:hasType(uri, 'integer') then
278282
vm.setNode(source, vm.declareGlobal('type', 'integer'))
@@ -395,9 +399,7 @@ vm.binarySwitch = util.switch()
395399
[1] = a .. b,
396400
})
397401
else
398-
local uri = guide.getUri(source)
399-
local infer1 = vm.getInfer(source[1])
400-
local infer2 = vm.getInfer(source[2])
402+
local uri, infer1, infer2 = getOperandInfers(source)
401403
if (
402404
infer1:hasType(uri, 'integer')
403405
or infer1:hasType(uri, 'number')

script/vm/value.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ function vm.getInteger(v)
139139
hasNonInteger = true
140140
end
141141
end
142-
if hasNonInteger and not result then
142+
if hasNonInteger then
143143
result = nil
144144
end
145145
-- If value not found via compiled node, try the local's

0 commit comments

Comments
 (0)