Skip to content

Commit 7374a42

Browse files
committed
fix: tl types: never trigger ICE on bad files
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.
1 parent 433d716 commit 7374a42

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

tl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,10 +897,15 @@ do
897897
env.keep_going = true
898898
env.report_types = true
899899

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

912917
local ok, _, _, w = report_all_errors(tlconfig, env)
918+
if not pcalls_ok then
919+
ok = false
920+
end
913921

914922
if not env.reporter then
915923
os.exit(1)
@@ -928,7 +936,7 @@ do
928936
x = tonumber(x) or 1
929937
json_out_table(io.stdout, tl.symbols_in_scope(tr, y, x, filename))
930938
else
931-
tr.symbols = tr.symbols_by_file[filename]
939+
tr.symbols = tr.symbols_by_file[filename] or { [0] = false }
932940
json_out_table(io.stdout, tr)
933941
end
934942

0 commit comments

Comments
 (0)