Skip to content

Commit

Permalink
fix: tl types: never trigger ICE on bad files
Browse files Browse the repository at this point in the history
This matches the behavior of master.

Can't make a simple regression test for this one because that
would be dependent on unspecified behaviors of the parser and
type-checker.

Fixes #795.
  • Loading branch information
hishamhm committed Aug 26, 2024
1 parent 433d716 commit 7374a42
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions tl
Original file line number Diff line number Diff line change
Expand Up @@ -897,10 +897,15 @@ do
env.keep_going = true
env.report_types = true

local pcalls_ok = true
for i, input_file in ipairs(args["file"]) do
local pok, perr, err = pcall(process_module, input_file, env)
-- we run the type-checker even on files that produce
-- syntax errors; this means we run it on incomplete and
-- potentially inconsistent trees which may crash the
-- type-checker; hence, we wrap it with a pcall here.
local pok, _, err = pcall(process_module, input_file, env)
if not pok then
die("Internal Compiler Error: " .. perr)
pcalls_ok = false
end
if err then
printerr(err)
Expand All @@ -910,6 +915,9 @@ do
end

local ok, _, _, w = report_all_errors(tlconfig, env)
if not pcalls_ok then
ok = false
end

if not env.reporter then
os.exit(1)
Expand All @@ -928,7 +936,7 @@ do
x = tonumber(x) or 1
json_out_table(io.stdout, tl.symbols_in_scope(tr, y, x, filename))
else
tr.symbols = tr.symbols_by_file[filename]
tr.symbols = tr.symbols_by_file[filename] or { [0] = false }
json_out_table(io.stdout, tr)
end

Expand Down

0 comments on commit 7374a42

Please sign in to comment.