You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)
Target: x86_64-apple-darwin18.7.0
Additional Detail from JIRA
Votes
0
Component/s
Compiler
Labels
Bug
Assignee
None
Priority
Medium
md5: 676c169994993b20be4fcd51d6ae65ff
Issue Description:
Int.dividedReportingOverflow(by: x) should return (x, true) when x = 0 however under some conditions the compiler fails with an error: division by zero:
And I believe a valid solution would be to make “Division by zero” (and in general, any arithmetic overflow) not be a compile-time error at all.
• • •
Swift has taken a principled stance that “trapping is safe”. Swift programs trap on overflow, on out-of-bounds, and on precondition failure. There is even a dedicated function fatalError() in the standard library whose entire purpose is to trap.
Programmers are allowed, and in many cases expected and encouraged, to write code that traps. The fact that a line of code will trap is, therefore, absolutely and emphatically not cause to prevent compilation.
If a programmer writes code that will always trap (such as fatalError() or division by zero) it is self-evident that they want the program to crash if execution reaches that line. This is a normal and standard practice in Swift.
Therefore, arithmetic overflow should not be a compile-time error at all. In fact, it should probably not even be a warning. Because trapping is safe.
Environment
Linux ubuntu18.04
swift-DEVELOPMENT-SNAPSHOT-2019-11-26-a-ubuntu18.04
macOS 10.14.6
Apple Swift version 5.1 (swiftlang-1100.0.270.13 clang-1100.0.33.7)
Target: x86_64-apple-darwin18.7.0
Additional Detail from JIRA
md5: 676c169994993b20be4fcd51d6ae65ff
Issue Description:
Int.dividedReportingOverflow(by: x)
should return(x, true)
whenx = 0
however under some conditions the compiler fails with anerror: division by zero
:If the divisor is not constant it works correctly
The same occurs for
remainderReportingOverflow(dividingBy🙂
Thanks to @gwynne for determining it was a compiler issue.
The text was updated successfully, but these errors were encountered: