Skip to content

Commit

Permalink
issue #211 since the up-value carries the type of the local variable,…
Browse files Browse the repository at this point in the history
… we can safely infer that the result of a get on array is a primitive type
  • Loading branch information
dibyendumajumdar committed Feb 18, 2021
1 parent 25dbc31 commit 9bceadd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
19 changes: 19 additions & 0 deletions tests/language/ravi_tests1.ravi
Original file line number Diff line number Diff line change
Expand Up @@ -1819,6 +1819,25 @@ end
check(x, 'TOIARRAY', 'IARRAY_GET', 'LEN', 'ADD', 'RETURN', 'RETURN')
print 'Test 86 OK'

-- An upvalue that is an array will yield a primitive value
-- issue #211
do
local x: integer[] = {4}
local y: number[] = {4.2}
local function f()
return x[1] + 1, y[1] + 2.2
end
check(f, 'GETTABUP', 'ADDII', 'GETTABUP', 'ADDFF', 'RETURN', 'RETURN')
local a,b = f()
assert(a == 5)
assert(b == 6.4)
compile(f)
a,b = f()
assert(a == 5)
assert(b == 6.4)
end
print 'Test 87 OK'


for k,v in pairs(opcodes_coverage)
do
Expand Down
17 changes: 8 additions & 9 deletions tests/language/ravi_tests2.ravi
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,11 @@ end
print 'Ok'

-- issue
--do
-- local function f(x:integer[])
-- return function ()
-- return x[1][1] + 1
-- end
-- end
-- local x = f(table.intarray(3))
-- x()
--end
do
local x: integer[] = {4}
local y: number[] = {4.2}
local function f()
return x[1] + 1, y[1] + 2.2
end
ravi.dumplua(f)
end

0 comments on commit 9bceadd

Please sign in to comment.