There is hidden achievement to unlock in this setup.
First, we know that the "existential" type itself is a value type which has no value semantics unless it wraps another type with value semantics.
struct Existential<Value> {
// invisible to the user
var _value: Value
// forwards all members of Value
}
Now let's see our protocols:
protocol P0 {
// this is a `mutating set`
var x: Int { get set }
}
// protocol is class bound but it still has a `mutating set`
protocol P1: AnyObject, P0 {}
// protocol is class bound but now we re-defined the property
// which implies that the `set` becomes `nonmutating`, it's just
// implicit in this context
protocol P2: AnyObject, P0 {
var x: Int { get set }
}
// Non-class bound protocol with explicit `nonmutating set`
protocol P3: P0 {
var x: Int { get nonmutating set }
}
// class bound and implicit `nonmutating set` like P2
protocol P4: AnyObject {
var x: Int { get set }
}
Now think about how the following values would behave:
Existential<P0>.x = 1 // expected-error
Existential<P1>.x = 1 // expected-error
Existential<P2>.x = 1 // okay
Existential<P3>.x = 1 // okay
Existential<P4>.x = 1 // okay - this is your first example
// your second example
Existential<P0 & AnyObject>.x = 1 // expected-error