swiftlang/swift

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

オープン

#53,798 opened on 2019/08/30

 (5 件のコメント) (0 件のリアクション) (1 人の担当者)Swift (10,719 件のフォーク)batch import
buggood first issuestandard library

Repository metrics

Stars
 (69,989 個のスター)
PR merge metrics
 (平均マージ 8d 17h) (30d で 510 merged PRs)

説明

Previous ID SR-11397
Radar None
Original Reporter CTMacUser (JIRA User)
Type Bug
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.)

コントリビューターガイド