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-10900] propertyDelegate type supersedes explicit type annotation #53290

Closed
keith opened this issue Jun 9, 2019 · 2 comments
Closed

[SR-10900] propertyDelegate type supersedes explicit type annotation #53290

keith opened this issue Jun 9, 2019 · 2 comments
Assignees
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

Comments

@keith
Copy link
Collaborator

keith commented Jun 9, 2019

Previous ID SR-10900
Radar None
Original Reporter @keith
Type Bug
Status Resolved
Resolution Done
Environment

Xcode 11.0 beta 1 (11M336w)

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

md5: 3fcf0f62c44720d56c042465fc0bc633

is duplicated by:

  • SR-11443 Property Wrapper overwrites type declaration

Issue Description:

If you have this code:

@propertyDelegate
struct Foo<Value> {
    var value: Value
    init(thing: Value) {
        self.value = thing
    }
}

let initial: Bool? = nil
struct Bar {
    @Foo(thing: initial) var thing: Bool
}

print(type(of: Bar().thing))

it outputs:

% DEVELOPER_DIR=/Applications/Xcode-11.0.0b1.app xcrun swift foo.swift
Optional<Bool>

In this case I'm surprised that this compiles, because I would expect the explicit `Bool` type annotation to have a mismatch with the property delegate's type. This further confused me because the compiler does error if they're entirely different types:

@propertyDelegate
struct Foo<Value> {
    var value: Value
    init(thing: Value) {
        self.value = thing
    }
}

struct Bar {
    @Foo(thing: "some string") var thing: Bool
}

this outputs:

% DEVELOPER_DIR=/Applications/Xcode-11.0.0b1.app xcrun swift foo.swift
foo.swift:10:6: error: cannot convert value of type 'Foo<String>' to specified type 'Bool'
    @Foo(thing: "some string") var thing: Bool
     ^~~~~~~~~~~~~~~~~~~~~~~~~

This might be by design because I did see some example from WWDC that was relying on the inference of a type like `Bool`, yet the property ended up being a `Optional<Bool>` but this surprised me overall since I didn't expect the property with an explicit type annotation to end up possibly being a different type

@belkadan
Copy link
Contributor

cc @DougGregor

@theblixguy
Copy link
Collaborator

Fixed by my PR: #27226

It now produces a diagnostic:

value of optional type 'Bool?' must be unwrapped to a value of type 'Bool'

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

No branches or pull requests

3 participants