swift: Bad diagnostic when inheriting from class in extension

The following errors are misleading and could use a rewording as clear language rules, depending on the kinds of extended and inherited types.

protocol P {}
struct S {}
class C1 {}
class C2 {}

extension C2: S {} // error: inheritance from non-protocol type 'S'
extension C2: C1 {} // error: inheritance from non-protocol type 'C1'
extension C2: C1 & P {} // error: inheritance from class-constrained protocol composition type 'C1 & P'

Environment

  • Swift version 5.9-dev (LLVM 6a04c4848990c70, Swift c1d5118c21d)

NB: How to improve on these is left as an exercise to whoever takes the issue.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Comments: 19 (3 by maintainers)

Most upvoted comments

I think the original vision of this issue is to rewrite the diagnostic message in the type check stage e.g. error: class can only inherit from protocol in extension declaration

@Aringopalan Please feel free to take it๐Ÿ˜Š