Skip to content

[TypeChecker] PropertyWrappers: Re-parent any captures from wrapped t… #61870

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

Merged
merged 1 commit into from
Nov 2, 2022

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Nov 2, 2022

…o backing property

In the situations where initializer of property wrapper attribute has any kind of captures i.e. { [x = ...] ... } they should be re-parented to the backing property because that's actually where the expression gets used - initializer of the backing property, e.g:

struct Test {
  @Wrapper([1, 2, 3].map { [x = 42] ... })
  var x: Int
}

is transformed into:

struct Test {
  var x: Int {
    get { ... }
    set { ... }
  }

  var _x: Wrapper<Int> = Wrapper(wrappedValue: [1, 2, 3].map { [x = 42] ... })
}

Resolves: #61570
Resolves: rdar://problem/101813792

@xedin xedin requested a review from hborla November 2, 2022 07:39
…o backing property

In the situations where initializer of property wrapper attribute
has any kind of captures i.e. `{ [x = ...] ... }` they should be
re-parented to the backing property because that's actually
where the expression gets used - initializer of the backing
property, e.g:

```swift
struct Test {
  @wrapper([1, 2, 3].map { [x = 42] ... })
  var x: Int
}
```

is transformed into:

```swift
struct Test {
  var x: Int {
    get { ... }
    set { ... }
  }

  var _x: Wrapper<Int> = Wrapper(wrappedValue: [1, 2, 3].map { [x = 42] ... })
}
```

Resolves: swiftlang#61570
Resolves: rdar://problem/101813792
@xedin
Copy link
Contributor Author

xedin commented Nov 2, 2022

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Nov 2, 2022

@swift-ci please test source compatibility

@xedin
Copy link
Contributor Author

xedin commented Nov 2, 2022

Looks like sandboxing issue with protobuf project has been fixed and it's now UPASS'ing.

@xedin xedin merged commit 59f1236 into swiftlang:main Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Property wrapper using a keypath leads to "Struct declaration cannot close over value '$kp$' defined in outer scope"
2 participants