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-7116] After capturing an implicitly unwrapped variable inside capture list it is not longer implicitly unwrapped optional #49664

Closed
swift-ci opened this issue Mar 4, 2018 · 2 comments
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

@swift-ci
Copy link
Collaborator

swift-ci commented Mar 4, 2018

Previous ID SR-7116
Radar None
Original Reporter arsen (JIRA User)
Type Bug
Status Resolved
Resolution Won't Do
Environment

Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)

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

md5: bb5fc23bc41fe6ae57f1baf171e707e8

Issue Description:

var optional: Int! = 0
 
// works
[1].map { value -> String in
    return optional.description
} 
// not works
[1].map { [number = optional] value -> String in
    return number.description // an error
}

The error:

error: repl.swift:3:12: error: value of optional type 'Int?' not unwrapped; did you mean to use '!' or '?'?
return number.description

The variable number has Int? type but optional has Int! type.

But in the same time the following code works:

var optional: Int? = 0
[1].map { [number = optional!] value -> String in
    return number.description
}
@belkadan
Copy link
Contributor

belkadan commented Mar 5, 2018

I think this is correct behavior. When an ImplicitlyUnwrappedOptional is evaluated, the implicitly-unwrapped-ness goes away. You can see that with a capture list like [number = optional + 1].

@rudkx, any further comments?

@rudkx
Copy link
Member

rudkx commented Mar 5, 2018

This is the expected behavior. Uses of things declared IUO that can be type checked as plain optional are, and in simple assignment where the result type is inferred, it will always type check when treated as an optional.

@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

3 participants