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-12233] Type inference not working with property wrapper? #54659

Closed
swift-ci opened this issue Feb 19, 2020 · 1 comment
Closed

[SR-12233] Type inference not working with property wrapper? #54659

swift-ci opened this issue Feb 19, 2020 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself property wrappers Feature: property wrappers type checker Area → compiler: Semantic analysis

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-12233
Radar None
Original Reporter danielctull (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

Swift 5.1, Swift 5.2

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

md5: 6e2736eef3570f149b65e252a002be75

duplicates:

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

Issue Description:

When using a property wrapper with a generic function, the type inference seems not to work. The following code shows the issue, which can also be found as a swift package here: https://github.com/danielctull-tests/PropertyWrapperInferenceTest

@propertyWrapper
struct Wrapper<Value> {
    var wrappedValue: Value?
}

func ifLet<Value, Result>(_ value: Value?, then: (Value) -> Result) -> Result? {
    value.map(then)
}

struct Foo {

    @Wrapper var value: Int?

    // Gives the following compiler error:
    // Cannot convert value 'value' of type 'String?' to expected type
    // 'Wrapper<String>?', use wrapper instead
    var bar: String? { ifLet(value, then: { String($0) }) }

    // This works fine.
    var baz: String? { ifLet(_value.wrappedValue, then: { String($0) }) }

    // And this works too.
    var qux: String? { ifLet(value as Int?, then: { String($0) }) }
}

It seems that when using value, the compiler is inferring the wrapper rather than the wrapped value.

Manifests with:

  • Xcode 11.3.1 (11C504)

  • Xcode 11.4 beta (11N111s)

  • Docker images:

    • swift:5.1

    • swiftlang/swift:nightly-5.2 (Swift version 5.2-dev (Swift 1933cc7))

    • swiftlang/swift:nightly (Swift version 5.2-dev (LLVM 89a551f, Swift 4b2b436))

Failing builds can be found here: https://github.com/danielctull-tests/PropertyWrapperInferenceTest/actions/runs/41808784

@theblixguy
Copy link
Collaborator

Fixed on master by #30129 You can verify using the next available development snapshot!

@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 property wrappers Feature: property wrappers type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants