swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.3k stars 10.34k forks source link

[SR-14674] ”Must be a 'var'” policy for property wrappers clashes a bit w/ properties of mutability model #57025

Open dabrahams opened 3 years ago

dabrahams commented 3 years ago
Previous ID SR-14674
Radar rdar://problem/78698175
Original Reporter @dabrahams
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 9174fa57d73b8e794f0cabbdb6ab7f77

Issue Description:

Consider this}}

/// A property wrapper that stores an arbitrary type while erasing its value
/// from consideration as part of equaltity, much like `Array.capacity`.
@propertyWrapper
struct Incidental<T>: Hashable {
  var wrappedValue: T

  static func == (_:Self, _:Self) -> Bool { true }
  func hash(into _: inout Hasher) {  }
}

Now if I want to make an immutable incidental value, I have to build ImmutableIncidental. It's a wonderful property of Swift that we don't generally end up with Foo and MutableFoo types, but here that property breaks down. I think there's sort of an implicit assumption that wrapped properties are “pointer-like,” but this one is not.

typesanitizer commented 3 years ago

@swift-ci create