New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-7353] Invalid error and warning related to recursive constraints on associated type #49901
Comments
Comment by Erik Little (JIRA) Also seeing a similar error with 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
} |
The error seems weird, but as you say, it seems like that's gone away with the development snapshot, for the first example. (FWIW, based on my analysis below, it seems like you actually don't need both @DougGregor: The requirement signature ends up being I still see errors with the second example, but only when all of the associated types exist: deleting, say, |
@swift-ci create |
Here's what I get for my second example with dev snapshot 2018-06-08:
So the error is gone, but the warning is a bug since that conformance is clearly not redundant. @huonw: "The error seems weird, but as you say, it seems like that's gone away with the development snapshot, for the first example. (FWIW, based on my analysis below, it seems like you actually don't need both B and C for the first case: the only way to conform to that protocol ends up with them being equal.)" Note that the first example has never been meant to demonstrate a bug (it's clearly stated in the report), it was just meant to illustrate why the second should work, just like the first. |
The following variant crashes the default toolchain of Xcode 10 beta, and dev snapshot 2018-06-08 produces the compile time errors below.
Error for X: 'P' requires the types 'X<T>' and 'X<Y<X<T>>>' be equivalent The following compiles though:
|
Environment
Xcode 9.3, default toolchain and eg dev snapshot 2018-03-28
Additional Detail from JIRA
md5: c26cdc0dbaf628a2e81a170395fe5d27
Issue Description:
Note that the following compiles as expected (in Xcode 9.3):
But adding a second associated type `C` to `Q` will produce the following invalid error and warning:
BUT: The error goes away (but not the warning) if the protocol definitions are swapped, so that Q is defined before P. Also, there is no error when using eg dev snapshot 2018-03-28, no matter the order of P and Q.
The text was updated successfully, but these errors were encountered: