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-7975] Fetching a nonexistent entry from a dictionary returns Optional<Any> when inferred type is Any #50509

Closed
0xpablo opened this issue Jun 12, 2018 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@0xpablo
Copy link

0xpablo commented Jun 12, 2018

Previous ID SR-7975
Radar None
Original Reporter @0xpablo
Type Bug
Status Resolved
Resolution Invalid
Environment

Swift version 4.2 (swiftlang-1000.0.16.4 clang-1000.0.25.3) (Xcode 10 b1 version)

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

md5: 70dcd571eb932fc888f8fe5e27f96a5d

relates to:

  • SR-8704 Cast from Any? to as? Value where Value == Any produces unexpected result in Xcode 10

Issue Description:

I'm seeing a weird behavior on Swift 4.2 when fetching values from a dictionary and casting them to Any.

To give more background, we have a storage that wraps a dictionary. The type of the underlying dictionary is [String: Any]?.
We typically access this from Swift with the following subscript:

@belkadan
Copy link
Contributor

I'm not sure about your actual project, but the behavior of your REPL interactions makes sense to me. You've got a value of type Optional<Any>, and you try to convert that (statically or dynamically) to Any. The "easiest" way to do that conversion is to put the Optional itself in another layer of Any, without looking at what's inside.

@0xpablo
Copy link
Author

0xpablo commented Jun 17, 2019

Makes sense, closing this

@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

2 participants