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-12093] Checked Casts With Literals Are Deeply Unintuitive #54529

Open
CodaFi opened this issue Jan 28, 2020 · 5 comments
Open

[SR-12093] Checked Casts With Literals Are Deeply Unintuitive #54529

CodaFi opened this issue Jan 28, 2020 · 5 comments
Labels
casting Feature: explicit casting (is, as, as? and as!) compiler The Swift compiler in itself improvement literals Feature → expressions: Literals such as an integer or string literal swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal

Comments

@CodaFi
Copy link
Member

CodaFi commented Jan 28, 2020

Previous ID SR-12093
Radar rdar://problem/58999135
Original Reporter @CodaFi
Type Improvement
Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Improvement, StarterProposal
Assignee inatonix (JIRA)
Priority Medium

md5: f23b80191801a31166f6b799915c7a23

cloned from:

  • SR-11421 Checked Cast Diagnostics Should Be More Specific When Literals Are Involved

Issue Description:

Checked casts on literals can have surprising effects at face value

let character = "A" as Character
let bad = "A" as? Character

The former is a character literal and is statically coerced. The latter is a String literal that is being dynamically cast to a Character. This cast will always fail, and we note as much - this also works with as! force casts.

warning: cast from 'String' to unrelated type 'Character' always fails

This behavior is deeply unintuitive and should be revisited by a proposal to unify casting semantics for literals.

@beccadax
Copy link
Contributor

@swift-ci create

@LucianoPAlmeida
Copy link
Collaborator

Just for reference, link to a PR related to the cloned bug #29493

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 6, 2020

Comment by shuya inada (JIRA)

Is it okay to tackle on this task? This is my first commit for Swift.

@CodaFi
Copy link
Member Author

CodaFi commented Apr 7, 2020

inatonix (JIRA User) You should know that this might involve a lot of work up front for one's first bug. You'll need to take a look at all the places where we aren't consistent between the static and dynamic coercions, figure out what we're missing, and draw up a proposal that provides a unified and consistent semantics for the two. Then you'll need to implement your proposal and drive it through evolution.

If this still sounds like a path you'd like to pursue, then by all means let me know how I can help. But if you're interest in a separate starter bug recommendation, I can give that too.

@swift-ci
Copy link
Collaborator

swift-ci commented Apr 8, 2020

Comment by shuya inada (JIRA)

@CodaFi Thank you for your comment! I got it, this problem sounds pretty difficult as my first task on Swift.. Do you have any recommendation task like separated starter bugs as the first contribution to Swift?

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added casting Feature: explicit casting (is, as, as? and as!) swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal literals Feature → expressions: Literals such as an integer or string literal and removed StarterProposal labels Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
casting Feature: explicit casting (is, as, as? and as!) compiler The Swift compiler in itself improvement literals Feature → expressions: Literals such as an integer or string literal swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal
Projects
None yet
Development

No branches or pull requests

5 participants