Skip to content

Commit

Permalink
fix: resolve nominals at lower scope levels
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Jan 23, 2023
1 parent 9547441 commit fe1a3f7
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 12 deletions.
39 changes: 39 additions & 0 deletions spec/declaration/nominal_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
local util = require("spec.util")

describe("nominals", function()
it("references get resolved in the same scope", util.check([[
-- unresolved nominal reference
local has_unr: function(where: Node)
-- circular type definitions
local type MyFn = function(MyMap)
local type MyMap = {string:MyFn}
-- above nominal reference gets resolved
local record Node
end
has_unr = function(where: Node)
print(where)
end
]]))

it("references get resolved across scopes", util.check([[
-- unresolved nominal reference
local has_unr: function(where: Node)
do
-- circular type definitions
local type MyFn = function(MyMap)
local type MyMap = {string:MyFn}
end
-- above nominal reference gets resolved
local record Node
end
has_unr = function(where: Node)
print(where)
end
]]))
end)
15 changes: 9 additions & 6 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8332,14 +8332,17 @@ tl.type_check = function(ast, opts)
end

local function dismiss_unresolved(name)
local unresolved = st[#st]["@unresolved"]
if unresolved then
if unresolved.t.nominals[name] then
for _, t in ipairs(unresolved.t.nominals[name]) do
resolve_nominal(t)
for i = #st, 1, -1 do
local unresolved = st[i]["@unresolved"]
if unresolved then
if unresolved.t.nominals[name] then
for _, t in ipairs(unresolved.t.nominals[name]) do
resolve_nominal(t)
end
unresolved.t.nominals[name] = nil
return
end
end
unresolved.t.nominals[name] = nil
end
end

Expand Down
15 changes: 9 additions & 6 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -8332,14 +8332,17 @@ tl.type_check = function(ast: Node, opts: TypeCheckOptions): Result, string
end

local function dismiss_unresolved(name: string)
local unresolved = st[#st]["@unresolved"]
if unresolved then
if unresolved.t.nominals[name] then
for _, t in ipairs(unresolved.t.nominals[name]) do
resolve_nominal(t)
for i = #st, 1, -1 do
local unresolved = st[i]["@unresolved"]
if unresolved then
if unresolved.t.nominals[name] then
for _, t in ipairs(unresolved.t.nominals[name]) do
resolve_nominal(t)
end
unresolved.t.nominals[name] = nil
return
end
end
unresolved.t.nominals[name] = nil
end
end

Expand Down

0 comments on commit fe1a3f7

Please sign in to comment.