[SR-12441] Compilation errors involving the usage of struct property wrappers declared in constrained extensions on generic types #54880
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
compiler
The Swift compiler in itself
performance
property wrappers
Feature: property wrappers
type checker
Area → compiler: Semantic analysis
Additional Detail from JIRA
md5: ec32305d51f3ca4dcb6da07d073fcf9f
Issue Description:
I've found an apparent compiler bug introduced in Swift 5.2, and I've whittled the code which reproduces it down as far as it will go. I have explored many small variations of this code, the conclusions of which I'll detail here.
Here's the first player in this mess:
By itself, this code compiles successfully.
The issue is when trying to use this new property wrapper:
With Swift 5.2 we get this error: `Illegal instruction: 4`.
Variations and Consequences
Firstly, if we change B from a struct to a class (and add the necessary initializer which was being synthesized when it was a struct) then the error switches to `Segmentation fault: 11`.
If we change the type of foo from B's generic parameter U to anything else, the code builds successfully:
This is also true if B is a class.
If B is a class and we make foo private (or fileprivate) then we get a successful build:
If B is a struct, however, then foo being private only fixes the `Illegal instruction: 4` error if we leave the initializer implicit. By contrast, if we use the explicit initializer that we just wrote so that B could be a class, but now we switch it back to a struct (with foo still being private) then we get `Illegal instruction: 4`. Unsurprisingly, if foo is public then we get errors for both the class and the struct.
If the property wrapper, Array.A, is a class then everything compiles successfully no matter what:
If the property wrapper is declared at the top level instead of inside the extension then the code builds successfully:
If the property wrapper is declared inside an extension of a non-generic type then the code builds successfully:
If the property wrapper is declared inside of an unconstrained extension on a generic type with the generic parameter being specified at the call site then the code builds successfully:
That's all I know about it. It has caused some code of mine to stop compiling, which I can work around for now, but of course will be appreciative whenever the fix arrives. Thanks for reading!
The text was updated successfully, but these errors were encountered: