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

Fix String.concat ignoring the len parameter #2723

Merged
merged 4 commits into from May 30, 2018

Conversation

patroclos
Copy link
Contributor

The loop pushing values from iter didn't increment n, resulting in finite iterators getting concated completely.

Also infinite iterators such as Iter.repeat_value would result in the function never returning and eating up memory.

This behavior contradicts the docstring.

The loop pushing values from iter didn't increment n, resulting in finite iterators getting concated completely.
Also infinite iterators such as `Iter.repeat_value` would result in the function never returning and eating up memory.
@@ -880,12 +880,14 @@ actor Main

n = 0

while n < len do
while (n < len) or (len == USize(-1)) do
Copy link
Member

Choose a reason for hiding this comment

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

what's the len == USize(-1) case?

Copy link
Member

Choose a reason for hiding this comment

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

nvm, i went and looked at the surrounding code. given that len == -1 is the default, i suspect the ordering should be reversed. if -1 is the most common, we should test for that first.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the default value of len is -1, meaning the amount of values to read should not be limited.
but now that you say it, being unsigned, this could be omitted

Copy link
Member

Choose a reason for hiding this comment

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

ah right. sorry. sick and not quite with it today.

@SeanTAllen
Copy link
Member

@patroclos can you add a test case for this so we don't get a regression?

fun name(): String => "builtin/String.concat"

fun apply(h: TestHelper) =>
h.assert_eq[String](recover String .> concat("ABCD".values(), 1, 2) end, "BC")
Copy link
Member

Choose a reason for hiding this comment

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

to match with standard library programming style, this should be String.>concat

@SeanTAllen SeanTAllen added the changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge label May 29, 2018
@SeanTAllen
Copy link
Member

Thanks @patroclos. This is an awesome first contribution. I hope it is the first of many.

@SeanTAllen SeanTAllen merged commit b4ba520 into ponylang:master May 30, 2018
ponylang-main added a commit that referenced this pull request May 30, 2018
@dipinhora dipinhora mentioned this pull request May 31, 2018
@patroclos patroclos deleted the patch-1 branch June 1, 2018 20:17
dipinhora pushed a commit to dipinhora/ponyc that referenced this pull request Jun 5, 2018
dipinhora pushed a commit to dipinhora/ponyc that referenced this pull request Jun 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog - fixed Automatically add "Fixed" CHANGELOG entry on merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants