Skip to content

add strict type checking for tuple#452

Closed
yashsain wants to merge 0 commit into
lcompilers:mainfrom
yashsain:main
Closed

add strict type checking for tuple#452
yashsain wants to merge 0 commit into
lcompilers:mainfrom
yashsain:main

Conversation

@yashsain

@yashsain yashsain commented May 6, 2022

Copy link
Copy Markdown
Contributor

Fixes #433

Comment thread src/libasr/asr_utils.h Outdated
case ASR::ttypeType::Tuple: {
return "tuple";
ASR::Tuple_t *t = (ASR::Tuple_t *)t;
return "tuple[" + type_to_str_python(t->m_type) + "]";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The issue is here. The t->m_type is a list of types (pointer to pointer), and there is t->n_type terms (I think). So just loop over them, and print it like tuple[i32, f64, str, ...].

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

thanks for the review, I will try to make changes to it.

@Thirumalai-Shaktivel Thirumalai-Shaktivel May 7, 2022

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yup, do something similar to this:

for (size_t i=0; i < m->n_dependencies; i++) {
std::string dep = m->m_dependencies[i];

replace dependencies with type and use the std::string variable to store all the type's information...

@certik

certik commented May 6, 2022

Copy link
Copy Markdown
Contributor

Otherwise this looks good, I think that is how it should be done. Thanks for working on it.

Comment thread tests/errors/test_tuple1.py Outdated
t: tuple[i32, str]
t = (1, 2)

main() No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
main()
main()

Comment thread tests/tests.toml Outdated

[[test]]
filename = "errors/test_tuple1.py"
asr = true No newline at end of file

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
asr = true
asr = true

@Smit-create

Copy link
Copy Markdown
Collaborator

Ah, I mistakenly closed this with a forced update, not sure why? Opened #495 with @yashsain 's initial commit

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.

Add strict type checking in tuple

4 participants