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

[SR-11397] FixedWidthInteger.init?(_: radix:) fails for Self with short bitWidth #53798

Open
swift-ci opened this issue Aug 30, 2019 · 5 comments
Assignees
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. good first issue Good for newcomers standard library Area: Standard library umbrella

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-11397
Radar None
Original Reporter CTMacUser (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, StarterBug
Assignee @theblixguy
Priority Medium

md5: 71036ce9352bad83dc05a0cfcdea3df7

Issue Description:

The current implementation of FixedWidthInteger.init?(_: radix: ) converts the radix to the receiver type. If that type has less than 6 bits of width, not all radix values are supported and a run error happens at the conversion.

Theoretically, any width above zero should work if we go to a bignum implementation. I'm not suggesting we do that, but that workaround indicates we shouldn't return a nil from the initializer in such cases, because that would imply a user error and not a implementation error. I guess a fatal error is more appropriate.

(BTW, my code was testing with a zero-width type, so there may be other problems.)

@stephentyrone
Copy link
Member

This should be pretty easy to fix for someone interested in this aspect of the stdlib. It's mostly just a matter of replumbing `_parseASCII` to take the `radix` parameter as an `Int` instead of `Result`. This would actually be a nice performance optimization in some cases anyway.

Good starter bug.

@theblixguy
Copy link
Collaborator

PR: #26961

@swift-ci
Copy link
Collaborator Author

Comment by Andreas Jönsson (JIRA)

If this one is still open I'd like to give it a try @stephentyrone, @theblixguy?

@theblixguy
Copy link
Collaborator

I haven’t found the time to address the review comment on my PR, but I’ll be doing that soon. Perhaps you can look for another StarterBug?

@swift-ci
Copy link
Collaborator Author

Comment by Andreas Jönsson (JIRA)

Sure thing! 🙂 And thanks for the quick reply.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. good first issue Good for newcomers standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants