Skip to content

Commit

Permalink
Added error tests for un-equal types in do loop
Browse files Browse the repository at this point in the history
  • Loading branch information
czgdp1807 committed Jan 6, 2023
1 parent 1fe650e commit e52422c
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/errors/loop_01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from ltypes import i16

def test_increment():
i: i16
for i in range(15, i16(-1), i16(-1)):
print(i)

test_increment()
8 changes: 8 additions & 0 deletions tests/errors/loop_02.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from ltypes import i16

def test_increment():
i: i16
for i in range(i16(15), i16(-1), -1):
print(i)

test_increment()
13 changes: 13 additions & 0 deletions tests/reference/asr-loop_01-e7aa06a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-loop_01-e7aa06a",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/loop_01.py",
"infile_hash": "dfe89b806a2b527a01526e9e55edc1271783e1ab916245222b561dee",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-loop_01-e7aa06a.stderr",
"stderr_hash": "256fe74af3480ca97b87c1b6f770cee10753e5f097d5a2d79135e736",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-loop_01-e7aa06a.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in loop start and loop end values, the types must be compatible
--> tests/errors/loop_01.py:5:20
|
5 | for i in range(15, i16(-1), i16(-1)):
| ^^ ^^^^^^^ type mismatch ('i32' and 'i16')
13 changes: 13 additions & 0 deletions tests/reference/asr-loop_02-5741651.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-loop_02-5741651",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/loop_02.py",
"infile_hash": "e88f2cac76a9de67c851a22a64cdae4553321d80ae64f5720a424a15",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-loop_02-5741651.stderr",
"stderr_hash": "a8262496250102a77a9e5718d40aaf1067fb21a18fb047885aa643ac",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-loop_02-5741651.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in loop start and increment values, the types must be compatible
--> tests/errors/loop_02.py:5:20
|
5 | for i in range(i16(15), i16(-1), -1):
| ^^^^^^^ ^^ type mismatch ('i16' and 'i32')
8 changes: 8 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -950,6 +950,14 @@ asr = true
filename = "errors/enum_02.py"
asr = true

[[test]]
filename = "errors/loop_01.py"
asr = true

[[test]]
filename = "errors/loop_02.py"
asr = true

[[test]]
filename = "errors/test_goto.py"
asr = true
Expand Down

0 comments on commit e52422c

Please sign in to comment.