Allow $ prefix fields in protocols

Seeing as it’s not possible to use Property Wrappers inside a protocol, there’s no way for a requirement using a $ prefix to conflict. It should be possible for protocols to have a requirement that is fulfilled by something implicitly synthesized. This is already possible with synthesized inits.

So this should be valid:

class FooViewModel: ViewModel, ObservableObject {
    @Published var viewState: FooViewState
}

protocol ViewModel<VS> {
    associatedtype VS
    var viewState: VS { get }
    var $viewState: Published<VS>.Publisher { get }
}

Currently this results in the error `Cannot declare entity named '$viewState'; the '$' prefix is reserved for implicitly-synthesized declarations`

7 Likes