Currently, we diagnose the following with an error:
protocol P {}
struct S : P, P {} // error: Duplicate inheritance from 'P'
What's the rationale for this being an error rather than a warning? As I understand it, errors are for programs that aren't well-formed, but the above seems well-formed to me – the additional P
in the inheritance clause is redundant and should therefore just be ignored (this is different from multiple inheritance with classes, which I agree should be illegal – that's currently its own error).
This is also the case with protocol "inheritance", where the types in the inheritance clause behave more like constraints than inherited types:
protocol P : AnyObject, AnyObject {} // error: Duplicate inheritance from 'AnyObject'
(we actually also emit a "Redundant constraint 'Self' : 'AnyObject'" warning from GSB for this, which is what I would have expected)
I'm asking because I'm currently in the middle of implementing a patch that emits a warning for redundant : Any
constraints and conformances over at [Sema][GSB] Warn about redundant ': Any' conformances & constraints by hamishknight · Pull Request #17425 · apple/swift · GitHub. Currently, I've put the warning logic for redundant : Any
conformances above the check for duplicate inheritance, meaning that we'll no longer emit an error for code like this (just two warnings):
struct S : Any, Any {}
I thought that accepting this would be okay while implementing the patch (it makes the diagnostics cleaner at least, rather than 2 warnings and an error), but now I'm having second thoughts. Should we continue to reject the above with an error? (and same for code like protocol P : Any, Any {}
?).