Skip to content

Commit

Permalink
issue #127 IDIV operation should cause result type to be marked as in…
Browse files Browse the repository at this point in the history
…teger type when type checking
  • Loading branch information
Dibyendu Majumdar committed Jun 30, 2017
1 parent 56f0480 commit 3470206
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
10 changes: 10 additions & 0 deletions ravi-tests/ravi_tests1.ravi
Original file line number Diff line number Diff line change
Expand Up @@ -1443,6 +1443,16 @@ compile(test_upvaluejoin);
assert(pcall(test_upvaluejoin));
print 'Test 55 Ok'

function test_idiv(y: integer)
local era: integer
era = y // 400
return era
end
check(test_idiv, 'TOINT', 'LOADNIL', 'LOADIZ', 'IDIV', 'RETURN', 'RETURN')
assert(test_idiv(1900) == 4)
compile(test_idiv)
assert(test_idiv(1900) == 4)
print 'Test 56 Ok'

for k,v in pairs(opcodes_coverage)
do
Expand Down
4 changes: 4 additions & 0 deletions src/lcode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,10 @@ static void codebinexpval (FuncState *fs, OpCode op,
else if ((op == OP_DIV)
&& e1->ravi_type == RAVI_TNUMINT && e2->ravi_type == RAVI_TNUMINT)
e1->ravi_type = RAVI_TNUMFLT;
else if ((op == OP_IDIV)
&& (e1->ravi_type == RAVI_TNUMINT || e1->ravi_type == RAVI_TNUMFLT)
&& (e2->ravi_type == RAVI_TNUMINT || e2->ravi_type == RAVI_TNUMFLT))
e1->ravi_type = RAVI_TNUMINT;
else if ((op == OP_BAND || op == OP_BOR || op == OP_BXOR || op == OP_SHL || op == OP_SHR)
&& e1->ravi_type == RAVI_TNUMINT && e2->ravi_type == RAVI_TNUMINT)
e1->ravi_type = RAVI_TNUMINT;
Expand Down

0 comments on commit 3470206

Please sign in to comment.