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-3535] divideWithOverflow gives Overflow error with edge case #46123

Closed
swift-ci opened this issue Jan 4, 2017 · 3 comments
Closed

[SR-3535] divideWithOverflow gives Overflow error with edge case #46123

swift-ci opened this issue Jan 4, 2017 · 3 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jan 4, 2017

Previous ID SR-3535
Radar None
Original Reporter PeterWAWood (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

MacBook 2.5ghz Intel Core I7, macOS 10.12.2, Xcode 8.2.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: ed4206a13cf1c4db0bfb3f93be5acea8

relates to:

  • SR-5964 dividedReportingOverflow may fail to compile for calculations that overflow

Issue Description:

The statement - Int.divideWithOverflow(Int.min, -1) - will give an overflow error.

Here is an extract of playground output when the statement is entered:

Playground execution failed: error: MyPlayground.playground:1:5: error: division     '-9223372036854775808 / -1' results in an overflow
Int.divideWithOverflow(Int.min, -1)
    ^

* thread #​1: tid = 0x2d8fad, 0x0000000103035360 com.apple.dt.Xcode.PlaygroundStub-macosx`executePlayground, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1

I checked on the Swift ML and was advised that this is expected. I am raising this issue as I feel that this "exception" needs to be documented.

@belkadan
Copy link
Contributor

belkadan commented Jan 4, 2017

cc @dabrahams, @natecook1000

@dabrahams
Copy link
Collaborator

IMO, this should not be expected. The error is a compile-time error from a function that is supposed to report at runtime whether there would be an overflow. Failing to compile this is akin to generating an error on the expression 1+1 == 2 just because its result is known to be true at compile-time.

@belkadan
Copy link
Contributor

belkadan commented Jan 4, 2017

Oh, sorry! I misread and thought it was a run-time error. Yes, the compiler should allow this when calling divideWithOverflow rather than plain /.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
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. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

3 participants