Skip to content

Commit b0dd053

Browse files
committed
more work on ranges
1 parent 9fec487 commit b0dd053

4 files changed

Lines changed: 15 additions & 8 deletions

File tree

nattlua/analyzer/mutation_tracking.lua

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ return function(META)
175175
end
176176

177177
function META:TrackUpvalueUnion(obj, truthy_union, falsy_union, inverted)
178+
if not truthy_union or not falsy_union then debug.trace() error() end
178179
local upvalue = obj:GetUpvalue()
179180

180181
if not upvalue then return end
@@ -468,8 +469,12 @@ return function(META)
468469

469470
union:SetUpvalue(data.upvalue)
470471
end
471-
472-
self:MutateUpvalue(data.upvalue, union, true)
472+
473+
if data.stack[#data.stack] and data.stack[#data.stack].falsy and data.stack[#data.stack].falsy.Type == "range" then
474+
self:MutateUpvalue(data.upvalue, data.stack[#data.stack].falsy:Copy(), true)
475+
else
476+
self:MutateUpvalue(data.upvalue, union, true)
477+
end
473478
end
474479
end
475480
end

nattlua/analyzer/operators/binary.lua

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,13 @@ end
146146
local intersect_comparison = require("nattlua.analyzer.intersect_comparison")
147147

148148
local function number_comparison(self, l, r, op, invert)
149-
local nl, nr = intersect_comparison(l, r, op, invert)
150-
151-
if nl and nr then self:TrackUpvalueUnion(l, nl, nr) end
149+
local nl, nr, nl2, nr2 = intersect_comparison(l, r, op, invert)
150+
151+
if nl and nr then
152+
self:TrackUpvalueUnion(l, nl, nr)
153+
end
152154

153-
if nr and nl then self:TrackUpvalueUnion(r, nr, nl) end
155+
if nl2 and nr2 then self:TrackUpvalueUnion(r, nl2, nr2) end
154156

155157
if nl and nr then
156158
if nl:IsNan() or nr:IsNan() then

test/tests/nattlua/analyzer/function.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ do
979979
local left = i * len + 1
980980
local right = left + len - 1
981981
attest.equal(left, _ as 1 .. inf)
982-
attest.equal(right, _ as 0 .. inf)
982+
attest.equal(right, _ as 1 .. inf)
983983
local res = str:sub(left, right)
984984
attest.equal(res, _ as string)
985985

test/tests/nattlua/analyzer/number.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ analyze[[
8282
]]
8383
analyze[[
8484
local n = _ as 0 .. 5
85-
if n > 1 then attest.equal(n, _ as 2 .. 5) else attest.equal(n, _ as 0 .. 5) end
85+
if n > 1 then attest.equal(n, _ as 2 .. 5) else attest.equal(n, _ as 0 .. 1) end
8686
]]
8787
analyze[[
8888
local a = _ as 1 .. 2

0 commit comments

Comments
 (0)