Skip to content

Commit

Permalink
fix: tl types: ensure symbols table matches first file
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Aug 21, 2024
1 parent dcf9889 commit 05b51c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
20 changes: 13 additions & 7 deletions spec/cli/types_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ describe("tl types works like check", function()
print(add1(10, 20))
]])
local name2 = util.write_tmp_file(finally, [[
local function add2(a: number, b: number): number
return a + b
local function add2(x: number, y: number): number
return x + y
end
print(add2(10, 20))
Expand All @@ -131,11 +131,17 @@ describe("tl types works like check", function()
local output = pd:read("*a")
util.assert_popen_close(0, pd:close())
local types = json.decode(output)
assert.same({
["a"] = 1,
["add2"] = 370,
["b"] = 1,
}, types)
local n = 0
for _ in pairs(types) do
n = n + 1
end
assert(n == 3)
assert(type(types["a"]) == "number")
assert(type(types["add1"]) == "number")
assert(type(types["b"]) == "number")
assert(type(types["x"]) == "nil")
assert(type(types["add2"]) == "nil")
assert(type(types["y"]) == "nil")
end)

it("reports number of errors in stderr and code 1 on syntax errors", function()
Expand Down
4 changes: 3 additions & 1 deletion tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10814,7 +10814,9 @@ function tl.get_types(result, trenv)
end
end

tr.symbols = tr.symbols_by_file[filename]
if not tr.symbols then
tr.symbols = tr.symbols_by_file[filename]
end

return tr, trenv
end
Expand Down
4 changes: 3 additions & 1 deletion tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -10814,7 +10814,9 @@ function tl.get_types(result: Result, trenv: TypeReportEnv): TypeReport, TypeRep
end
end

tr.symbols = tr.symbols_by_file[filename]
if not tr.symbols then
tr.symbols = tr.symbols_by_file[filename]
end

return tr, trenv
end
Expand Down

0 comments on commit 05b51c6

Please sign in to comment.