Skip to content

Commit

Permalink
fix: ensure poly types rollback stack is consistent
Browse files Browse the repository at this point in the history
Fixes #915.
  • Loading branch information
hishamhm committed Jan 22, 2025
1 parent 157a7af commit 8e276e4
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
14 changes: 12 additions & 2 deletions spec/api/get_types_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,26 @@ describe("tl.get_types", function()
local record R
f: function(string)
f: function(integer)
g: function<X>(string, X): {X}
g: function<T>(integer, T): T
end
R.f("hello")
R.f(9)
local z = R.g(123, "hello")
]], env))

local tr, trenv = tl.get_types(result)
local y = 6
local y = 9
local x = 11
local type_at_y_x = tr.by_pos[""][y][x]
assert(tr.types[type_at_y_x].str == "function(string)")
assert.same(tr.types[type_at_y_x].str, "function(string)")

y = 11
x = 21
type_at_y_x = tr.by_pos[""][y][x]
assert.same(tr.types[type_at_y_x].str, "function(integer, T): T")
end)

it("reports record functions in record field list", function()
Expand Down
6 changes: 3 additions & 3 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8222,8 +8222,8 @@ do
end
end

function TypeChecker:begin_scope_transaction()
self:begin_scope()
function TypeChecker:begin_scope_transaction(node)
self:begin_scope(node)
local st = self.st
st[#st].is_transaction = true
end
Expand Down Expand Up @@ -10003,7 +10003,7 @@ a.types[i], b.types[i]), }
expected_rets = a_type(node, "tuple", { tuple = { node.expected } })
end

self:begin_scope_transaction()
self:begin_scope_transaction(node)

local g
local typeargs
Expand Down
6 changes: 3 additions & 3 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -8222,8 +8222,8 @@ do
end
end

function TypeChecker:begin_scope_transaction()
self:begin_scope()
function TypeChecker:begin_scope_transaction(node: Node)
self:begin_scope(node)
local st = self.st
st[#st].is_transaction = true
end
Expand Down Expand Up @@ -10003,7 +10003,7 @@ do
expected_rets = a_tuple(node, { node.expected })
end

self:begin_scope_transaction()
self:begin_scope_transaction(node)

local g: GenericType
local typeargs: {TypeArgType}
Expand Down

0 comments on commit 8e276e4

Please sign in to comment.