Skip to content

Commit 5334944

Browse files
authored
Merge pull request #2093 from Smit-create/i-2088
Fix 1-dim array length in message
2 parents d3852a4 + d936e85 commit 5334944

9 files changed

+48
-6
lines changed

src/libasr/asr_utils.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,9 @@ static inline std::string type_python_1dim_helper(const std::string & res,
10041004
}
10051005

10061006
if( ASRUtils::expr_value(e->m_length) ) {
1007-
int64_t length_dim = -1;
1007+
int64_t length_dim = 0;
10081008
ASRUtils::extract_value(ASRUtils::expr_value(e->m_length), length_dim);
1009-
return res + "[" + std::to_string(length_dim + 1) + "]";
1009+
return res + "[" + std::to_string(length_dim) + "]";
10101010
}
10111011

10121012
return res;

tests/errors/arrays_01.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from lpython import (i8, i32, dataclass)
2+
from numpy import empty, int8
3+
4+
# test issue-2088
5+
6+
@dataclass
7+
class LPBHV_small:
8+
dim : i32 = 4
9+
a : i8[4] = empty(4, dtype=int8)
10+
11+
12+
def g() -> None:
13+
l2 : LPBHV_small = LPBHV_small(
14+
4,
15+
[i8(214), i8(157), i8(3), i8(146)])
16+
17+
g()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "asr-arrays_01-a617b64",
3+
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
4+
"infile": "tests/errors/arrays_01.py",
5+
"infile_hash": "9e11033fc97f884cd3d55a9194cb45add6805e5fc4d9473f9e1b9611",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "asr-arrays_01-a617b64.stderr",
11+
"stderr_hash": "b8317c7306f747ceefa8557c06f2a0b4a8a4bd7ae805bb494fca6ef2",
12+
"returncode": 2
13+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
semantic error: Type mismatch in procedure call; the types must be compatible
2+
--> tests/errors/arrays_01.py:15:9
3+
|
4+
15 | [i8(214), i8(157), i8(3), i8(146)])
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch (passed argument type is list[i8] but required type is i8[4])
6+
|
7+
9 | a : i8[4] = empty(4, dtype=int8)
8+
| ^^^^^ type mismatch (passed argument type is list[i8] but required type is i8[4])

tests/reference/asr-test_annassign_type_mismatch-7dac7be.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "asr-test_annassign_type_mismatch-7dac7be.stderr",
11-
"stderr_hash": "a794ce35be79f7fcbb0889e04091555055f3c1c537bcf14840d33e60",
11+
"stderr_hash": "26fc89f95c7dda5f1d9c3cb1af9843880cf693eb7b97125372b11f80",
1212
"returncode": 2
1313
}

tests/reference/asr-test_annassign_type_mismatch-7dac7be.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ semantic error: Type mismatch in annotation-assignment, the types must be compat
22
--> tests/errors/test_annassign_type_mismatch.py:4:5
33
|
44
4 | x: i32[4] = [1, 2, 3, 4]
5-
| ^ ^^^^^^^^^^^^ type mismatch ('i32[5]' and 'list[i32]')
5+
| ^ ^^^^^^^^^^^^ type mismatch ('i32[4]' and 'list[i32]')

tests/reference/asr-test_annassign_type_mismatch2-fc883f7.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
"stdout": null,
99
"stdout_hash": null,
1010
"stderr": "asr-test_annassign_type_mismatch2-fc883f7.stderr",
11-
"stderr_hash": "3c2bbba713689c37ed22127cdd7a37ab6b1bce03d01380803884849d",
11+
"stderr_hash": "873b4521e2155bc92405db41e7745a4fb5441b5d80f94467d7b1b637",
1212
"returncode": 2
1313
}

tests/reference/asr-test_annassign_type_mismatch2-fc883f7.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ semantic error: Type mismatch in annotation-assignment, the types must be compat
22
--> tests/errors/test_annassign_type_mismatch2.py:4:5
33
|
44
4 | x: f64[5] = [1.0, 2.0, 3.0, 4.0, 5.0]
5-
| ^ ^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('f64[6]' and 'list[f64]')
5+
| ^ ^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('f64[5]' and 'list[f64]')

tests/tests.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,10 @@ asr = true
651651
filename = "errors/structs_01.py"
652652
asr = true
653653

654+
[[test]]
655+
filename = "errors/arrays_01.py"
656+
asr = true
657+
654658
[[test]]
655659
filename = "errors/structs_02.py"
656660
asr = true

0 commit comments

Comments
 (0)