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-14346] Document error #56705

Open
swift-ci opened this issue Mar 13, 2021 · 1 comment
Open

[SR-14346] Document error #56705

swift-ci opened this issue Mar 13, 2021 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. documentation

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-14346
Radar None
Original Reporter allennjusa (JIRA User)
Type Bug
Environment

Xcode 12.4 (12D4e)

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

md5: 5fac6185a515f864fb550d8e0fa22676

Issue Description:

https://docs.swift.org/swift-book/LanguageGuide/TheBasics.html

Optional Binding

You can rewrite the possibleNumber example from the Optionals section to use optional binding rather than forced unwrapping:

  1. if let actualNumber = Int(possibleNumber) {

  2. print("The string "(possibleNumber)" has an integer value of (actualNumber)")

  3. } else {

  4. print("The string "(possibleNumber)" couldn't be converted to an integer")

  5. }

This code can be read as:

"If the optional Int returned by Int(possibleNumber) contains a value, set a new constant called actualNumber to the value contained in the optional."

==============

Error:

The first line of code is wrong. The compiler will give this error message:
"Value of optional type 'Int?' must be unwrapped to a value of type 'Int'"

Need to change the document or change the compiler. Not sure which one is correct.

@typesanitizer
Copy link

Could you clarify what part of the code results in that error? Looking at https://godbolt.org/z/qb4Gjz, the code compiles fine without any error.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
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. documentation
Projects
None yet
Development

No branches or pull requests

2 participants