swiftlang/swift

Bad diagnostic when inheriting from class in extension

Open

#64,903 opened on Apr 4, 2023

View on GitHub
 (21 comments) (0 reactions) (1 assignee)Swift (10,719 forks)batch import
bugcompilerdiagnostics qualityextensiongood first issueinheritanceswift 6.0type checker

Repository metrics

Stars
 (69,989 stars)
PR merge metrics
 (Avg merge 8d 17h) (510 merged PRs in 30d)

Description

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.

Contributor guide