Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add error tests for mismatch in empty dtype #2307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tests/errors/arrays_03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from lpython import i16
from numpy import empty, int16

# checks dim mismatch for local array variable
def main0():
x: i16[4] = empty([5], dtype=int16)

main0()
8 changes: 8 additions & 0 deletions tests/errors/arrays_04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from lpython import i16
from numpy import empty, int32

# checks type mismatch for local array variable
def main0():
x: i16[5] = empty([5], dtype=int32)

main0()
8 changes: 8 additions & 0 deletions tests/errors/arrays_05.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from lpython import i16
from numpy import empty, int16

# checks multi-dim mismatch for local array variable
def main0():
x: i16[5, 4] = empty([5, 3], dtype=int16)

main0()
8 changes: 8 additions & 0 deletions tests/errors/arrays_06.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from lpython import i16
from numpy import empty, int32

# checks type mismatch for multi-dim local array variable
def main0():
x: i16[5, 4] = empty([5, 4], dtype=int32)

main0()
8 changes: 8 additions & 0 deletions tests/errors/arrays_07.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from lpython import f32
from numpy import empty, complex64

# checks type mismatch for types apart from integers
def main0():
x: f32[5, 4] = empty([5, 4], dtype=complex64)

main0()
11 changes: 11 additions & 0 deletions tests/errors/arrays_08.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from lpython import i32, i64, Const
from numpy import empty, int64

# checks multi-dim mismatch when constant variables are used as dimensions
def main0():
p: Const[i32] = 100
q: Const[i32] = 120
r: Const[i32] = 200
x: i64[p, q, r] = empty([q, p, r], dtype=int64)

main0()
11 changes: 11 additions & 0 deletions tests/errors/arrays_09.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from lpython import i32, i64
from numpy import empty, int64

# checks using runtime variables as value for multi-dims
def main0():
p: i32 = 100
q: i32 = 120
r: i32 = 200
x: i64[p, q, r] = empty([q, p, r], dtype=int64)

main0()
11 changes: 11 additions & 0 deletions tests/errors/arrays_10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from lpython import i32, i64
from numpy import empty, int64

# checks using runtime variables as value for multi-dims of emtpy()
def main0():
p: i32 = 100
q: i32 = 120
r: i32 = 200
x: i64[100, 120, 200] = empty([q, p, r], dtype=int64)

main0()
5 changes: 5 additions & 0 deletions tests/errors/arrays_11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from lpython import i16
from numpy import empty, int16

# Checks dim mismatch for global array variables
x: i16[4] = empty([5], dtype=int16)
5 changes: 5 additions & 0 deletions tests/errors/arrays_12.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from lpython import i16
from numpy import empty, int32

# Checks type mismatch for global array variables
x: i16[5] = empty([5], dtype=int32)
9 changes: 9 additions & 0 deletions tests/errors/arrays_13.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from lpython import i16
from numpy import empty, int16

# checks dim mismatch for local array variable
# when dim is specified as a constant integer
def main0():
x: i16[4] = empty(5, dtype=int16)

main0()
9 changes: 9 additions & 0 deletions tests/errors/arrays_14.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from lpython import i16
from numpy import empty, int16

# checks dim mismatch for local array variable
# when dim is specified as a tuple
def main0():
x: i16[4] = empty((5), dtype=int16)

main0()
13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_03-de2e952.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_03-de2e952",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_03.py",
"infile_hash": "429c486d84e37401f89fe1e678039ae0e16b2cf5bf13417767160858",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_03-de2e952.stderr",
"stderr_hash": "4c932f31bbb10c9ba8d8d75be226ba9c33553be3bcb367c8112e31af",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_03-de2e952.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/arrays_03.py:6:5
|
6 | x: i16[4] = empty([5], dtype=int16)
| ^ ^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('i16[4]' and 'i16[5]')
13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_04-880407c.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_04-880407c",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_04.py",
"infile_hash": "9dfe40ad5fd610b75685a45ffd700ff14e263738dd5ba968952d7874",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_04-880407c.stderr",
"stderr_hash": "10ef155b0236096d5de8157e38b3989d99343b016a8153b68a36aa54",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_04-880407c.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/arrays_04.py:6:5
|
6 | x: i16[5] = empty([5], dtype=int32)
| ^ ^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('i16[5]' and 'i32[5]')
13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_05-ec8fbd5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_05-ec8fbd5",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_05.py",
"infile_hash": "c525449694f73038495a6bd8fded408301f43d18b1c387765b92b792",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_05-ec8fbd5.stderr",
"stderr_hash": "b92b252106c95d1851599993abbedd755f2b3231f5b551b3af33b67e",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_05-ec8fbd5.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/arrays_05.py:6:5
|
6 | x: i16[5, 4] = empty([5, 3], dtype=int16)
| ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('i16[5][4]' and 'i16[5][3]')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would write it as i16[5, 4] as in the source code, not i16[5][4].

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you also suggest to include the start value of the dimension? For example i16[0:5, 0:4]? I guess it is only helpful for the developers. For users it might confuse as python does not have lower_bounds. (Although it could be helpful in the case for LFortran if we reuse this printing mechanism/function there.)

We can also include the start value of the dimension later (when we have more experience with error messages or user feedback).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For Python I would print it as just i16[5, 4]. For LFortran we use a different method to print the type, and there indeed we have an option to print the dimension in the usual Fortran notation --- depending on the context, sometimes the lower dimension matters, sometimes it doesn't.

13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_06-fbb09a3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_06-fbb09a3",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_06.py",
"infile_hash": "670cbcac5e942bae5293cd94090bab65a2039384d71fb8be4c6db5a1",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_06-fbb09a3.stderr",
"stderr_hash": "0cd2825fa152a45c868b7f54832a95d0f457be296143f28ce1909870",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_06-fbb09a3.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/arrays_06.py:6:5
|
6 | x: i16[5, 4] = empty([5, 4], dtype=int32)
| ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('i16[5][4]' and 'i32[5][4]')
13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_07-de430fd.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_07-de430fd",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_07.py",
"infile_hash": "efe8b3c4a474aca55cb8a537a3ea2cd30eb5d5abf140d8c2c0b9e3f4",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_07-de430fd.stderr",
"stderr_hash": "ea9cadd25ae52d3ff115925e4f8e6feb278ad009410d64c940cf64ff",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_07-de430fd.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/arrays_07.py:6:5
|
6 | x: f32[5, 4] = empty([5, 4], dtype=complex64)
| ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('f32[5][4]' and 'c32[5][4]')
13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_08-ba317a3.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_08-ba317a3",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_08.py",
"infile_hash": "3f7a5a8889301df17222a777f7e92a5667097ffca9ac4d275ccb310f",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_08-ba317a3.stderr",
"stderr_hash": "a6fc0e1c661fab5e3ee0a034abb85d765a1dce515483a2a6191b2aa7",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_08-ba317a3.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/arrays_08.py:9:5
|
9 | x: i64[p, q, r] = empty([q, p, r], dtype=int64)
| ^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('i64[100][120][200]' and 'i64[120][100][200]')
13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_09-50ee586.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_09-50ee586",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_09.py",
"infile_hash": "e6f2cca7de4ecfddffdc96ee4c278de35c220b608c9e4fe4731fd9b8",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_09-50ee586.stderr",
"stderr_hash": "30bfc87e70c4b4688cf7162eec34dce8e52c959539d20ad8b79cf845",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_09-50ee586.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Only those local variables which can be reduced to compile time constant should be used in dimensions of an array.
--> tests/errors/arrays_09.py:9:12
|
9 | x: i64[p, q, r] = empty([q, p, r], dtype=int64)
| ^
13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_10-bc82d75.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_10-bc82d75",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_10.py",
"infile_hash": "05aedf3d1013c61f73afc3de4ddca88ee33f029dcd62fadb66e7ec83",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_10-bc82d75.stderr",
"stderr_hash": "59e8cc91d7dae61bf60ec4d9cd23d62cdcb162e553bd64a3995fad19",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_10-bc82d75.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Only those local variables which can be reduced to compile time constant should be used in dimensions of an array.
--> tests/errors/arrays_10.py:9:36
|
9 | x: i64[100, 120, 200] = empty([q, p, r], dtype=int64)
| ^
13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_11-fc505b4.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_11-fc505b4",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_11.py",
"infile_hash": "111b4224a1988a90dc091fda4e0b1ebfd096f25f7b4ccc2f13728c1c",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_11-fc505b4.stderr",
"stderr_hash": "ef5e89392b20ad345ba9bcf862ab71b19e56c85d9838db742be117a1",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_11-fc505b4.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/arrays_11.py:5:1
|
5 | x: i16[4] = empty([5], dtype=int16)
| ^ ^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('i16[4]' and 'i16[5]')
13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_12-63d6f25.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_12-63d6f25",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_12.py",
"infile_hash": "03cc809a4ee6a2ff47b5a91111d26e501ded647478e7fa03bde5bdf7",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_12-63d6f25.stderr",
"stderr_hash": "b6fa626301868bd5cbbef6d914f5b4f38b1d896b951753122969e74a",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_12-63d6f25.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/arrays_12.py:5:1
|
5 | x: i16[5] = empty([5], dtype=int32)
| ^ ^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('i16[5]' and 'i32[5]')
13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_13-b5fcc7e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_13-b5fcc7e",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_13.py",
"infile_hash": "6aa585e55d5ba97e0c139b1a86268b41104955236fc6f87a11771505",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_13-b5fcc7e.stderr",
"stderr_hash": "6bde2f7fc14d5a461a58d694e44e19dd79ef5bee47c88b4022daf5d6",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_13-b5fcc7e.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/arrays_13.py:7:5
|
7 | x: i16[4] = empty(5, dtype=int16)
| ^ ^^^^^^^^^^^^^^^^^^^^^ type mismatch ('i16[4]' and 'i16[5]')
13 changes: 13 additions & 0 deletions tests/reference/asr-arrays_14-78be00e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-arrays_14-78be00e",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/errors/arrays_14.py",
"infile_hash": "f724b8a5dfe7bc481f465e6f9105c9a2e6a8b7a5985a63ba52b58db2",
"outfile": null,
"outfile_hash": null,
"stdout": null,
"stdout_hash": null,
"stderr": "asr-arrays_14-78be00e.stderr",
"stderr_hash": "267aea8e48708230a9b2bc61c37c849a0b75cb45294ca25ee11fe632",
"returncode": 2
}
5 changes: 5 additions & 0 deletions tests/reference/asr-arrays_14-78be00e.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
semantic error: Type mismatch in annotation-assignment, the types must be compatible
--> tests/errors/arrays_14.py:7:5
|
7 | x: i16[4] = empty((5), dtype=int16)
| ^ ^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('i16[4]' and 'i16[5]')
Loading