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

Support string repeat with non constant integer #2675

Conversation

kmr-srbh
Copy link
Contributor

fixes #2652

my_string: str = "#"
n: i32 = 5

print(my_string * n)
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
#####

@kmr-srbh
Copy link
Contributor Author

@Shaikh-Ubaid the following, unrelated to the changes in the PR, fails:

my_string: str = "#"
repeated_string: str = my_string * -1

print(repeated_string)
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
malloc(): corrupted top size
Aborted (core dumped)

An assert statement had checked for this case before, but interestingly the assertion did not fail. The error is observed when we try to use the obtained value, either by trying to print it, or store it.

@kmr-srbh
Copy link
Contributor Author

@Shaikh-Ubaid after you approve these changes, I will make the changes stated in https://github.com/lcompilers/lpython/pull/2651/files#r1573132771

@kmr-srbh kmr-srbh force-pushed the support-string-repeat-with-non-constant-integer branch from 36cd4a9 to 25b4c0e Compare April 30, 2024 11:05
src/lpython/semantics/python_ast_to_asr.cpp Outdated Show resolved Hide resolved
src/lpython/semantics/python_ast_to_asr.cpp Outdated Show resolved Hide resolved
integration_tests/test_str_01.py Outdated Show resolved Hide resolved
@kmr-srbh kmr-srbh requested a review from Shaikh-Ubaid May 1, 2024 03:44
Copy link
Collaborator

@Shaikh-Ubaid Shaikh-Ubaid left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for this!

@Shaikh-Ubaid Shaikh-Ubaid merged commit 973c500 into lcompilers:main May 1, 2024
14 checks passed
@kmr-srbh kmr-srbh deleted the support-string-repeat-with-non-constant-integer branch May 2, 2024 13:58
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.

Improvement: Support string repeat with a non-constant integer
2 participants