-
Notifications
You must be signed in to change notification settings - Fork 159
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
Implement Set #91
Implement Set #91
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should start with extending our type system with Set and Dict, and then go from there. See above.
ASR:
|
Seems like this is true in the above-produced ASR. |
|
||
a = {1, 2, 3} | ||
a = {2, 3, 4, 5, 5} | ||
a = {"a", "b", "c"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these should give an error message that "Set[i32] (or character) cannot be assigned to i32".
Then let's add tests like:
a: Set[i32]
a = {1, 2, 3}
And we need to improve the assignment to do this check.
Yes, this looks very good. The RHS seems correct in ASR. The Assignment is incorrect, as you cannot assign a set to an integer, see my comment above. You can only assign a set to a set. |
I know, just I was planning to add the |
Here are examples of typing: https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html#built-in-types, let's use the same syntax |
Let's move the improvement of the assignment to a separate PR? I know many tests will fail once I apply this diff: diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp
index bc7bb209..72fe972d 100644
--- a/src/lpython/semantics/python_ast_to_asr.cpp
+++ b/src/lpython/semantics/python_ast_to_asr.cpp
@@ -515,7 +515,11 @@ public:
}
this->visit_expr(*x.m_value);
ASR::expr_t *value = ASRUtils::EXPR(tmp);
- ASR::stmt_t *overloaded=nullptr;
+ ASR::stmt_t *overloaded = nullptr;
+ if (!ASRUtils::check_equal_type(ASRUtils::expr_type(target), ASRUtils::expr_type(value))) {
+ throw SemanticError("Assignment types do not match",
+ x.base.base.loc);
+ }
tmp = ASR::make_Assignment_t(al, x.base.base.loc, target, value,
overloaded);
} |
We can't merge this PR anyway until we run all tests in LFortran, so we have to do that. |
I did so -- no test failures. |
Awesome. Would you mind please sending a Merge Request against LFortran with this change in ASR? Let's get it merged there first. Then we'll come back and finish this PR. |
MR opened: !1650. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same comment as for the dictionary. I think this is ok to merge.
The ConstantSet creation is correct. But declaring a set and assignment to it does not generate a correct ASR yet, but we can fix that later.
No description provided.