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-8816] Spurious type checker failure with ExpressibleByIntegerLiteral #51324

Closed
lorentey opened this issue Sep 21, 2018 · 3 comments
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@lorentey
Copy link
Member

Previous ID SR-8816
Radar None
Original Reporter @lorentey
Type Bug
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 963d5e6afdeb87fb37fe05df83293fe2

Issue Description:

The following code (extracted from Swift NIO) compiles and runs correctly on Swift 4.2, but fails on current master:

struct UInt24: ExpressibleByIntegerLiteral {
  init(integerLiteral value: UInt16) {}
  init(_ value: UInt32) {}
}
print(UInt24(100_000)) // error: integer literal '100000' overflows when stored into 'UInt16'
@belkadan
Copy link
Contributor

I think this is a deliberate change per SE-0213. Hm. @xedin, thoughts?

@xedin
Copy link
Member

xedin commented Sep 21, 2018

Yes, that's deliberate. All of the `ExpressibleBy*` types are going to use initialization via coercion, to use old behavior you can call initializer explicitly e.g. `UInt24.init(100_000)`

@Lukasa
Copy link
Contributor

Lukasa commented Sep 24, 2018

Ok, sounds reasonable enough for a breaking change. I'll update SwiftNIO to fix the issue. Thanks @xedin!

@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 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

4 participants