Skip to content

Raise error for a type mismatch in annassign #370

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
Apr 21, 2022

Conversation

namannimmo10
Copy link
Collaborator

No description provided.

@certik
Copy link
Contributor

certik commented Apr 14, 2022

Can you please add a test for this error?

--> tests/errors/test_annassign_type_mismatch.py:4:5
|
4 | x: i32[4] = [1, 2, 3, 4]
| ^ ^^^^^^^^^^^^ type mismatch (integer and list)
Copy link
Contributor

Choose a reason for hiding this comment

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

So the type on the left is not just an integer, but an array of integers. So we should improve the error message to say it is an array.

Copy link
Contributor

Choose a reason for hiding this comment

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

An idea what this can print is at #398 (comment), but that's longer term. As part of this PR or a next PR, we change just print it as:


4 |     x: i32[4] = [1, 2, 3, 4]
  |     ^           ^^^^^^^^^^^^ type mismatch (i32[4] and list[i32])

We can do this by changing ASRUtils::type_to_str to ASRUtils::type_to_str_python and this function would print the type as i32[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.

I'll open a new PR for that soon. Thanks. We definitely need excellent and self-explanatory error messages.

@namannimmo10 namannimmo10 merged commit b23f661 into lcompilers:main Apr 21, 2022
@namannimmo10 namannimmo10 deleted the annassign branch April 21, 2022 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants