Skip to content

Commit 030ee45

Browse files
committed
get rid of scope cloning when an error occurs in a union operation
it's redundant as the way upvalues are tracked does a better job
1 parent 0aa0c3d commit 030ee45

5 files changed

Lines changed: 3 additions & 32 deletions

File tree

nattlua/analyzer/base/scopes.lua

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,6 @@ return function(META)
7676
return self.scope_stack
7777
end
7878

79-
function META:CloneCurrentScope()
80-
local scope_copy = self:GetScope():Copy()
81-
local g = self:GetGlobalEnvironment("runtime"):Copy()
82-
local last_node = self:GetContextValue("global_environment_nodes")
83-
self:PopScope()
84-
self:PopGlobalEnvironment("runtime")
85-
scope_copy:SetParent(scope_copy:GetParent() or self:GetScope())
86-
self:PushGlobalEnvironment(last_node, g, "runtime")
87-
self:PushScope(scope_copy)
88-
return scope_copy
89-
end
90-
9179
function META:IncrementUpvaluePosition()
9280
self.upvalue_position = (self.upvalue_position or 0) + 1
9381
return self.upvalue_position

nattlua/analyzer/control_flow.lua

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -376,12 +376,6 @@ return function(META)
376376
return scope
377377
end
378378

379-
function META:ErrorAndCloneCurrentScope(err)
380-
self:Error(err)
381-
self:CloneCurrentScope()
382-
self:GetScope():SetConditionalScope(true)
383-
end
384-
385379
function META:PopConditionalScope()
386380
self:PopScope()
387381
end

nattlua/analyzer/operators/binary.lua

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,8 @@ local function Binary(self, node, l, r, op)
332332
local res, err = Binary(self, node, l, r, op)
333333

334334
if not res then
335-
if type(err) == "string" then
336-
print(node, l,r,op)
337-
print(res, err, "?!?!!!")
338-
end
339-
self:ErrorAndCloneCurrentScope(err, l) -- TODO, only left side?
335+
self:Error(err)
340336
else
341-
if type(res) ~= "table" then
342-
print(res, err, l,op, r)
343-
debug.trace()
344-
error("HUH")
345-
end
346-
347337
if res:IsTruthy() then
348338
if type_checked then
349339
for _, t in ipairs(type_checked:GetData()) do

nattlua/analyzer/operators/call.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ local function union_call(self, analyzer, input, call_node)
2323
end
2424

2525
if v.Type ~= "function" and v.Type ~= "table" and v.Type ~= "any" then
26-
analyzer:ErrorAndCloneCurrentScope(type_errors.union_contains_non_callable(self, v), self--[[# as any]])
26+
analyzer:Error(type_errors.union_contains_non_callable(self, v))
2727
else
2828
truthy_union:AddType(v)
2929
end

nattlua/analyzer/operators/prefix.lua

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ local function Prefix(analyzer, node, r)
4949
local res, err = Prefix(analyzer, node, r)
5050

5151
if not res then
52-
analyzer:ErrorAndCloneCurrentScope(err, r)
53-
falsy_union:AddType(r)
52+
analyzer:Error(err)
5453
else
5554
new_union:AddType(res)
5655

0 commit comments

Comments
 (0)