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

Correction in list.pop #2235

Merged
merged 1 commit into from
Jul 31, 2023
Merged

Conversation

kabra1110
Copy link
Collaborator

Corrects implementation of list.pop. The while loop condition was incorrect.

@certik certik requested a review from czgdp1807 July 31, 2023 02:49
Copy link
Collaborator

@czgdp1807 czgdp1807 left a comment

Choose a reason for hiding this comment

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

Please add a test for which the main branch fails and your branch passes?

@czgdp1807 czgdp1807 marked this pull request as draft July 31, 2023 05:04
@kabra1110
Copy link
Collaborator Author

Please add a test for which the main branch fails and your branch passes?

If this line is changed to read_item(list, tmp, true, *module, false) (i.e., enabling bound checks), then a simple test like this shows the issue

from lpython import i32

def test_list_pop_corrected():
    l: list[i32] = []
    i: i32
    for i in range(10):
        l.append(i)
    print(l.pop(0))

test_list_pop_corrected()

This happens because l[tmp] is being accessed, but tmp = end_point happens (once).

@kabra1110 kabra1110 requested a review from czgdp1807 July 31, 2023 05:42
@czgdp1807 czgdp1807 marked this pull request as ready for review July 31, 2023 11:05
@czgdp1807 czgdp1807 enabled auto-merge (squash) July 31, 2023 11:05
@czgdp1807 czgdp1807 merged commit 9f02797 into lcompilers:main Jul 31, 2023
9 checks passed
kabra1110 added a commit to kabra1110/lpython that referenced this pull request Aug 4, 2023
Iterate only till the second last position.
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.

None yet

2 participants