Skip to content

Commit 5729417

Browse files
committed
numbers with max should not be considered literals
1 parent 0e2053f commit 5729417

File tree

5 files changed

+20
-17
lines changed

5 files changed

+20
-17
lines changed

examples/projects/luajit/src/platforms/unix/filesystem.nlua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ do
183183

184184
local dot = string.byte(".")
185185

186-
local function is_dots(ptr: FFIArray<|3, number|>)
186+
local function is_dots(ptr: {[number] = number})--FFIArray<|3, number|>)
187187
if ptr[0] == dot then
188188
if ptr[1] == dot and ptr[2] == 0 then return true end
189189

examples/projects/luajit/src/platforms/windows/filesystem.nlua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ do
122122
)
123123
local dot = string.byte(".")
124124

125-
local function is_dots(ptr: FFIArray<|3, number|>)
125+
local function is_dots(ptr: {[number] = number}) -- todo: maybe FFIArray<|12, number|> should be ok to pass when the argument contract is FFIArray<|3, number|> , because it's at least 3 in length
126126
if ptr[0] == dot then
127127
if ptr[1] == dot and ptr[2] == 0 then return true end
128128

nattlua/analyzer/operators/index.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ local function index_table(analyzer, self, key, raw)
9999
if key:IsLiteral() then
100100
local found_key = self:FindKeyValReverse(key)
101101

102-
if found_key and not found_key.key:IsLiteral() then
102+
if found_key and not found_key.key:IsLiteral() and not (found_key.key.Max) then
103103
val = Union({Nil(), val})
104104
end
105105
end

nattlua/types/number.lua

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function META.Equal(a--[[#: TNumber]], b--[[#: TBaseType]])
9999
end
100100

101101
function META:IsLiteral()
102-
return self.Data ~= false
102+
return self.Data ~= false and self.Max == false
103103
end
104104

105105
META:IsSet("DontWiden", false)
@@ -108,25 +108,28 @@ function META:Widen()
108108
return Number()
109109
end
110110

111-
function META:CopyLiteralness(num--[[#: TBaseType]])
112-
if self.ReferenceType == num.ReferenceType and self.Data == num.Data then
111+
function META:CopyLiteralness(obj--[[#: TBaseType]])
112+
if self.ReferenceType == obj.ReferenceType and self.Data == obj.Data then
113113
return self
114114
end
115115

116116
local self = self:Copy()
117117

118-
if num.Type ~= "number" or not num.Max then
119-
if num:IsReferenceType() then
120-
self:SetReferenceType(true)
121-
else
122-
if not num:IsLiteral() then self.Data = false end
123-
end
118+
if obj:IsReferenceType() then
119+
self:SetReferenceType(true)
124120
else
125-
if self:IsSubsetOf(num) then
126-
if num:IsReferenceType() then self:SetReferenceType(true) end
121+
if obj.Max then
122+
123+
else
124+
if obj.Type == "union" then
125+
local x = (obj --[[#as any]]):GetType("number")
126+
127+
if x then
128+
if x.Max then return self end
129+
end
130+
end
127131

128-
self:SetData(num.Data)
129-
self:SetMax(num.Max)
132+
if not obj:IsLiteral() then self.Data = false end
130133
end
131134
end
132135

test/tests/nattlua/analyzer/list.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ analyze([[local a: {[number] = any} = {foo = 1}]], [[has no key "foo"]])
3838
-- {[1 .. inf]: any}
3939
check(
4040
analyze[[local a: {[1 .. inf] = any} = {[1234] = 1}]],
41-
"{ [1..inf] = number as any }"
41+
"{ [1234 as 1..inf] = number as any }"
4242
)
4343

4444
check(analyze([[local a: {["a" | "b" | "c"] = 1 | 2 | 3} = {a = 2}]]), [[{ ["a" as "a" | "b" | "c"] = 2 as 1 | 2 | 3 }]])

0 commit comments

Comments
 (0)