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-13381] Cannot pass a property wrapper value to a generic function as an optional #55821

Open
swift-ci opened this issue Aug 12, 2020 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13381
Radar radar://FB8357142
Original Reporter daltonclaybrook (JIRA User)
Type Bug

Attachment: Download

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

md5: f743f34994c62c87be4e8fe7488ed556

duplicates:

  • SR-11654 Optional wrapped property can't be passed to generic function

Issue Description:

If the wrappedValue of a property wrapper is an Optional, you cannot pass it as the argument to a generic function with the signature:

func doSomething<T>(value: T?)

The following error is observed:

Cannot convert value 'wrapped' of type 'String?' to expected type 'Wrapped<String?>?', use wrapper instead

Full example:

@propertyWrapper
struct Wrapped<T> {
    let wrappedValue: T
}

struct Demo {
    @Wrapped
    var wrapped: String? = "abc"

    func attemptPassToGenericFunction() {
        // Error occurs here
        someGenericFunction(value: wrapped)
    }

    func thisWorks() {
        someGenericFunction(value: _wrapped.wrappedValue)
    }

    func someGenericFunction<T>(value: T?) {
        print(value)
    }
}
@theblixguy
Copy link
Collaborator

Looks like a dupe of SR-11654, which is fixed as of Swift 5.3. daltonclaybrook (JIRA User) could you test this with Xcode 12 beta or a development snapshot from swift.org?

@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.
Projects
None yet
Development

No branches or pull requests

2 participants