Skip to content
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

Merged
merged 8 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Register the test for Set
  • Loading branch information
namannimmo10 committed Jan 31, 2022
commit 1997034f563487df015f69fdf95dcca67d89b9ec
13 changes: 13 additions & 0 deletions tests/reference/asr-set1-b7b913a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "asr-set1-b7b913a",
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}",
"infile": "tests/set1.py",
"infile_hash": "9daf37483fb6f1523007506236ce239db1f9c56a31c5e028bbecff0b",
"outfile": null,
"outfile_hash": null,
"stdout": "asr-set1-b7b913a.stdout",
"stdout_hash": "9dde6562a377c4220974f0663dcabb38f57023373053bb00c19397ba",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
1 change: 1 addition & 0 deletions tests/reference/asr-set1-b7b913a.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(TranslationUnit (SymbolTable 1 {test_Set: (Subroutine (SymbolTable 2 {a: (Variable 2 a Local () () Default (Integer 4 []) Source Public Required .false.), b: (Variable 2 b Local () () Default (Integer 4 []) Source Public Required .false.)}) test_Set [] [(= (Var 2 a) (ConstantSet [(ConstantInteger 1 (Integer 4 [])) (ConstantInteger 2 (Integer 4 [])) (ConstantInteger 3 (Integer 4 []))] (Integer 4 [])) ()) (= (Var 2 a) (ConstantSet [(ConstantInteger 2 (Integer 4 [])) (ConstantInteger 3 (Integer 4 [])) (ConstantInteger 4 (Integer 4 [])) (ConstantInteger 5 (Integer 4 [])) (ConstantInteger 5 (Integer 4 []))] (Integer 4 [])) ()) (= (Var 2 a) (ConstantSet [(ConstantString "a" (Character 1 1 () [])) (ConstantString "b" (Character 1 1 () [])) (ConstantString "c" (Character 1 1 () []))] (Character 1 1 () [])) ()) (= (Var 2 b) (ArrayRef 2 a [(() (ConstantInteger 0 (Integer 4 [])) ())] (Integer 4 []) ()) ())] Source Public Implementation () .false. .false.)}) [])
13 changes: 13 additions & 0 deletions tests/reference/ast-set1-ebd6ee0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "ast-set1-ebd6ee0",
"cmd": "lpython --show-ast --no-color {infile} -o {outfile}",
"infile": "tests/set1.py",
"infile_hash": "9daf37483fb6f1523007506236ce239db1f9c56a31c5e028bbecff0b",
"outfile": null,
"outfile_hash": null,
"stdout": "ast-set1-ebd6ee0.stdout",
"stdout_hash": "8c1cad9ac254b1847c30e26721e705d4db36fca6316e0f4e870f06a0",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
1 change: 1 addition & 0 deletions tests/reference/ast-set1-ebd6ee0.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(Module [(FunctionDef test_Set ([] [] [] [] [] [] []) [(AnnAssign (Name a Store) (Name i32 Load) () 1) (AnnAssign (Name b Store) (Name i32 Load) () 1) (Assign [(Name a Store)] (Set [(ConstantInt 1 ()) (ConstantInt 2 ()) (ConstantInt 3 ())]) ()) (Assign [(Name a Store)] (Set [(ConstantInt 2 ()) (ConstantInt 3 ()) (ConstantInt 4 ()) (ConstantInt 5 ()) (ConstantInt 5 ())]) ()) (Assign [(Name a Store)] (Set [(ConstantStr "a" ()) (ConstantStr "b" ()) (ConstantStr "c" ())]) ()) (Assign [(Name b Store)] (Subscript (Name a Load) (ConstantInt 0 ()) Load) ())] [] () ())] [])
9 changes: 9 additions & 0 deletions tests/set1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def test_Set():
a: i32
b: i32

a = {1, 2, 3}
a = {2, 3, 4, 5, 5}
a = {"a", "b", "c"}
Copy link
Contributor

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.

# a = {-1, -2, "c"} -> semantic error for now
b = a[0]
Smit-create marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ filename = "assign1.py"
ast = true
asr = true

[[test]]
filename = "set1.py"
ast = true
asr = true

[[test]]
filename = "global_scope1.py"
ast = true
Expand Down