swiftlang / swift

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

[SR-14309] Weak causes property wrappers to crash the compiler #56668

Open phausler opened 3 years ago

phausler commented 3 years ago
Previous ID SR-14309
Radar rdar://problem/75116542
Original Reporter @phausler
Type Bug
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 22f6b77d5bcf375bef1d8264f1699a86

Issue Description:

The following code crashes the compiler:

@propertyWrapper
struct Container<Ref: AnyObject> {
  weak var wrappedValue: Ref?
}struct Item {
  @Container var foo: Foo?
}

But the following code compiles just fine:

@propertyWrapper
struct Container<Ref: AnyObject> {
 var wrappedValue: Ref?
}struct Item {
  @Container var foo: Foo?
}
typesanitizer commented 3 years ago

@swift-ci create

hborla commented 3 years ago

There are two issues here

  1. In asserts builds, the compiler hits an assertion failure because it expects a type to contain no type variables when computing the reference storage type of a member. I think we can just remove that assertion.

  2. In a non-asserts build, the compiler produces an error because it fails to drop the reference storage type before comparing the wrappedValue vs property type for equality On second thought, if you wrote a weak wrapped value in the property wrapper, you probably want the property you apply the wrapper to to become weak also.