You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A generic struct that is constrained to an AnyObject type parameter, and also conforms to SetAlgebra, will cause the compiler to miss non-conforming type parameters during initialization, leading to spurious errors and crashes on later use.
Consider the following type. Most of this is just required SetAlgebra conformance. The important parts are: conforms to SetAlgebra, and Element is constrained to AnyObject (i.e. must be a class).
However, when constructed with a struct, the compiler does not generate an error at the point of construction, but does generate spurious errors later.
vars2 = ClassSet<String>() // no error//s2.update(with: "") // cannot use mutating member on immutable values2.isEmpty// true
When constructed with an array literal, it will crash rather than generating a compiler error.
vars3: ClassSet<String> = [""] // EXC_BAD_ACCESS
The text was updated successfully, but these errors were encountered:
Environment
Apple Swift version 4.0.3 (swiftlang-900.0.74.1 clang-900.0.39.2)
OS X 10.13.2
Xcode 9.2
Additional Detail from JIRA
md5: 1987236c74d9f90f8c472c5250128184
Issue Description:
A generic struct that is constrained to an AnyObject type parameter, and also conforms to SetAlgebra, will cause the compiler to miss non-conforming type parameters during initialization, leading to spurious errors and crashes on later use.
Consider the following type. Most of this is just required SetAlgebra conformance. The important parts are: conforms to SetAlgebra, and Element is constrained to AnyObject (i.e. must be a class).
When constructed with a class, this type behaves as expected:
However, when constructed with a struct, the compiler does not generate an error at the point of construction, but does generate spurious errors later.
When constructed with an array literal, it will crash rather than generating a compiler error.
The text was updated successfully, but these errors were encountered: