Before I go about filing a bug. Could anyone explain what might be going on in this example.
// Having Phase above causes an error in GameRules
#if PHASE_ABOVE
public protocol Phase {
associatedtype RulesType: GameRules where RulesType.PhaseType == Self
}
#endif
public protocol GameRules {
associatedtype ContextType: GameContext where ContextType.RulesType == Self
associatedtype PhaseType: Phase where PhaseType.RulesType == Self
associatedtype PlayerType: Player where PlayerType.RulesType == Self
// Error here when `Phase` is above this protocol. Error: Instance method requirement cannot add constraint ... on Self
mutating func executeTurn(forPlayer player: PlayerType)
}
// But having it below is fine
#if !PHASE_ABOVE
public protocol Phase {
associatedtype RulesType: GameRules where RulesType.PhaseType == Self
}
#endif
public protocol GameContext : AnyObject {
associatedtype RulesType: GameRules where RulesType.ContextType == Self
}
public protocol Player : AnyObject, Hashable {
associatedtype RulesType: GameRules where RulesType.PlayerType == Self
}
tl;dr: Moving a protocol above another causes an error.
This seems to be an "improvement" over 4.0.3. There this just crashes the compiler.
Jens
4
Yeah possibly. Should I go ahead and attach my example to that ticket? And if they turn out to be different I’ll just make a new ticket.
Jens
6
I think you should file your example as a separate report, mentioning SR-7353 as possibly related.