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

Property Wrapper cannot be compiled correctly with $ in function body (Xcode 14 and main?) #59295

Closed
freddi-kit opened this issue Jun 7, 2022 · 5 comments · Fixed by #60384
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler itself property wrappers Feature: property wrappers type checker Area → compiler: Semantic analysis

Comments

@freddi-kit
Copy link
Contributor

freddi-kit commented Jun 7, 2022

Describe the bug
The code with Property Wrapper cannot be compiled correctly in Swift 5.7 dev (Xcode 14 dev)

import Foundation

@propertyWrapper
struct WrapperValue<Value> {
  var value: Value
  init(wrappedValue: Value) {
    self.value = wrappedValue
  }

  var projectedValue: Self {
    return self
  }
  
  var wrappedValue: Value {
    get {
      self.value  
    }
    set {
      self.value = newValue
    }
  }

  func printValue() {
    print(value)
  }
}


class Test {
  static func test() {
    (0..<100).map { _ in
      @WrapperValue var value: Bool = false

      if value {
        $value.printValue() // .. compile error on 5.7
      }
    }
  }
}

This code had been compiled until Swift 5.6.1.

I already send it to apple (FB10059129)

To Reproduce
Compile above code.

Expected behavior
Compile success.

Screenshots

<stdin>:35:9: error: cannot reference invalid declaration '$value'
        $value.printValue() // .. compile error on 5.7
        ^
<stdin>:32:25: note: '$value' declared here
      @WrapperValue var value: Bool = false
                        ^

Environment (please complete the following information):

  • Xcode 14 dev (14A5228q)
  • nightly (ee312bc)
@freddi-kit freddi-kit added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Jun 7, 2022
@freddi-kit
Copy link
Contributor Author

Hello, this stil fails nightly build, could anyone help checking it?

@xedin xedin added the type checker Area → compiler: Semantic analysis label Aug 2, 2022
@hank121314
Copy link
Contributor

hank121314 commented Aug 3, 2022

Smaller reproducer:

@propertyWrapper
struct WrapperValue {
  var value: Bool

  init(wrappedValue: Bool) {
    self.value = wrappedValue
  }

  var wrappedValue: Bool {
    get {
      self.value
    }
    set {
      self.value = newValue
    }
  }
}

let _ = { () -> () in
  @WrapperValue var value = false

  _value
}

xedin added a commit to xedin/swift that referenced this issue Aug 3, 2022
To support referencing projected and/or wrapped var
in a closure solver needs to lookup a type of their
originator and based on the wrapper type compute and
assign types to projection and/or wrapper.

Resolves: swiftlang#59295
Resolves: rdar://94506352
xedin added a commit to xedin/swift that referenced this issue Aug 3, 2022
To support referencing projected and/or wrapped var
in a closure solver needs to lookup a type of their
originator and based on the wrapper type compute and
assign types to projection and/or wrapper.

Resolves: swiftlang#59295
Resolves: rdar://94506352
xedin added a commit to xedin/swift that referenced this issue Aug 5, 2022
To support referencing projected and/or wrapped var
in a closure solver needs to lookup a type of their
originator and based on the wrapper type compute and
assign types to projection and/or wrapper.

Resolves: swiftlang#59295
Resolves: rdar://94506352
xedin added a commit to xedin/swift that referenced this issue Aug 5, 2022
To support referencing projected and/or wrapped var
in a closure solver needs to lookup a type of their
originator and based on the wrapper type compute and
assign types to projection and/or wrapper.

Resolves: swiftlang#59295
Resolves: rdar://94506352
(cherry picked from commit 0989f43)
@freddi-kit
Copy link
Contributor Author

In Swift 5.7, it is not fixed yet. Please check with the code example in this issue's description @xedin

@freddi-kit
Copy link
Contributor Author

freddi-kit commented Sep 16, 2022

$ swift --version
swift-driver version: 1.62.8 Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)
Target: arm64-apple-macosx12.0

This is investigated environment

@freddi-kit
Copy link
Contributor Author

it looks fixed on Xcode 14.1 RC, thanks

@AnthonyLatsis AnthonyLatsis added the compiler The Swift compiler itself label Dec 13, 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. compiler The Swift compiler itself property wrappers Feature: property wrappers type checker Area → compiler: Semantic analysis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants