Skip to content

Commit f1fab19

Browse files
committed
fix wrong syntax
1 parent 6192ba1 commit f1fab19

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

nattlua/definitions/lua/globals.nlua

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type _ = any
44
type @Name = "_G"
55
type rawlen = function=(v: Table | string)>(number)
66
type rawequal = function=(v1: any, v2: any)>(boolean)
7-
type collectgarbage = function=(opt: string, arg: number)>(...: any) | function=(opt: string)>(...: any) | function=()>(...: any)
7+
type collectgarbage = function=(opt: string, arg: number)>(...any) | function=(opt: string)>(...any) | function=()>(...any)
88

99
analyzer function type_print(...: ...any)
1010
print(...)
@@ -157,7 +157,7 @@ analyzer function require(name: string)
157157

158158
if val then return val end
159159
end
160-
160+
161161
if analyzer:GetLocalOrGlobalValue(str) then
162162
return analyzer:GetLocalOrGlobalValue(str)
163163
end
@@ -250,6 +250,7 @@ end
250250
analyzer function assert(...: ...any)
251251
local obj = select(1, ...)
252252
local potential_msg = select(2, ...)
253+
253254
if not analyzer:IsDefinetlyReachable() then
254255
analyzer:ThrowSilentError(obj)
255256

@@ -378,19 +379,18 @@ type xpcall = ReturnIfNonLiteral<|
378379
type select = ReturnIfNonLiteral<|
379380
analyzer function(index: 1 .. inf | "#", ...: ...any): ...any
380381
local x = ...
382+
381383
if x and x.Type == "tuple" then
382384
return select(index:GetData(), x:Unpack())
383385
end
384386

385387
return select(index:GetData(), ...)
386388
end
387389
|>
388-
389390
type select_type = analyzer function(index: 1 .. inf | "#", ...: ...any): ...any
390391
local x = ...
391-
if x and x.Type == "tuple" then
392-
return x:Slice(index:GetData())
393-
end
392+
393+
if x and x.Type == "tuple" then return x:Slice(index:GetData()) end
394394

395395
return select(index:GetData(), ...)
396396
end
@@ -445,6 +445,7 @@ end
445445

446446
analyzer function setmetatable(tbl: Table, meta: Table | nil)
447447
if tbl.Type == "any" then return tbl end
448+
448449
if not meta or meta.Type == "symbol" and meta:IsFalse() then
449450
tbl:SetMetaTable(false)
450451
return tbl

nattlua/parser/expressions.lua

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ do -- typesystem
127127
end
128128

129129
function META:ParseValueTypeExpression()
130-
if not self:IsTokenValue("...") then
131-
return
132-
end
130+
if not self:IsTokenValue("...") then return end
133131

134132
local node = self:StartNode("expression", "vararg")
135133
node.tokens["..."] = self:ExpectTokenValue("...")
134+
136135
if not self:GetToken().whitespace then
137136
node.value = self:ParseTypeExpression(0)
138137
end
138+
139139
node = self:EndNode(node)
140140
return node
141141
end
@@ -487,7 +487,20 @@ do -- typesystem
487487
return
488488
end
489489

490-
return self:ParseTypeExpression(priority)
490+
local exp = self:ParseTypeExpression(priority)
491+
492+
if not exp then
493+
local token = self:GetToken()
494+
self:Error(
495+
"faiiled to parse type expression, got $1",
496+
nil,
497+
nil,
498+
token and token.value ~= "" and token.value or token.type
499+
)
500+
return
501+
end
502+
503+
return exp
491504
end
492505
end
493506

0 commit comments

Comments
 (0)