Skip to content

Commit

Permalink
Merge pull request #607 from pallene-lang/tcc-gabrielsferreira
Browse files Browse the repository at this point in the history
Basic-blocks-based intermediate language and flow analysis.
  • Loading branch information
hugomg authored Jul 8, 2024
2 parents 3e2846a + 57c1837 commit 89851b6
Show file tree
Hide file tree
Showing 11 changed files with 892 additions and 744 deletions.
8 changes: 8 additions & 0 deletions spec/execution_tests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2318,6 +2318,14 @@ function execution_tests.run(compile_file, backend, _ENV, only_compile)
end
end
function m.non_breaking_loop2(): integer
local i = 1
repeat
if i == 42 then return i end
i = i + 1
until false
end
function m.initialize_inside_loop(): integer
local x: integer
repeat
Expand Down
55 changes: 55 additions & 0 deletions spec/uninitialized_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,61 @@ describe("Uninitialized variable analysis: ", function()
]], "variable 'x' is used before being initialized")
end)

it("catches use of uninitialized variable inside \"if\"", function()
assert_error([[
local m: module = {}
function m.foo()
local x:boolean
if x then end
end
return m
]], "variable 'x' is used before being initialized")
end)

it("catches use of uninitialized variable inside \"while\"", function()
assert_error([[
local m: module = {}
function m.foo()
local x:boolean
while x do end
end
return m
]], "variable 'x' is used before being initialized")
end)

it("catches use of uninitialized variable inside \"repeat until\"", function()
assert_error([[
local m: module = {}
function m.foo()
local x:boolean
repeat until x
end
return m
]], "variable 'x' is used before being initialized")
end)

it("catches use of uninitialized variable inside \"for\"", function()
assert_error([[
local m: module = {}
function m.foo()
local x:integer
for i = 1, x, x do end
end
return m
]], "variable 'x' is used before being initialized")
end)

it("catches use of uninitialized variable inside \"for in\"", function()
assert_error([[
local m: module = {}
function m.foo()
local x:{integer}
for i,j in ipairs(x) do end
end
return m
]], "variable 'x' is used before being initialized")
end)

it("catches use of uninitialized upvalue", function ()
assert_error([[
local m = {}
Expand Down
Loading

0 comments on commit 89851b6

Please sign in to comment.