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

Skip to content

Support array comparison #2157

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 4 commits into from
Jul 14, 2023
Merged

Support array comparison #2157

merged 4 commits into from
Jul 14, 2023

Conversation

ubaidsk
Copy link
Collaborator

@ubaidsk ubaidsk commented Jul 13, 2023

fixes #2135

@ubaidsk ubaidsk force-pushed the support_arr_comp branch from a04c498 to ff45349 Compare July 13, 2023 18:34
@ubaidsk ubaidsk requested a review from certik July 13, 2023 20:14
Copy link
Contributor

@certik certik left a comment

Choose a reason for hiding this comment

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

I think that looks good.

You can merge this, and in the next PR you can try to improve the error message to be more helpful, I provided some ideas.

@@ -0,0 +1,5 @@
semantic error: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Copy link
Contributor

Choose a reason for hiding this comment

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

How about this:

Suggested change
semantic error: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
semantic error: The truth value of an array with more than one element is ambiguous. Use any() or all()

--> tests/errors/arrays_02.py:28:8
|
28 | assert r1.a == t1.a
| ^^^^^^^^^^^^
Copy link
Contributor

Choose a reason for hiding this comment

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

And this:

help: use any(r1.a == t1.a) or all(r1.a == t1.a)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

help: use any(r1.a == t1.a) or all(r1.a == t1.a)

Here, we do not have access to the string r1.a == t1.a. When printing diagnostics the input file is read (from disk) and the error line/string is obtained form the read source input.

Shall we do the following?

help: use any() or all()

Or shall we keep the message as it is currently in the main branch?

Copy link
Contributor

Choose a reason for hiding this comment

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

We have access to AST and partial ASR, so we should be able to construct t1, r1 and a. And we know it's a struct access and we know it's a comparison. So you use this information to create the text any(r1.a == t1.a).

Copy link
Contributor

Choose a reason for hiding this comment

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

I made this #2159, so that we don't forget.

@ubaidsk ubaidsk merged commit 6be4353 into lcompilers:main Jul 14, 2023
@ubaidsk ubaidsk deleted the support_arr_comp branch July 14, 2023 10:21
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.

Equality test of i8 arrays correctly fails, but with wrong error message
2 participants