Skip to content

Incorrect 'class inherits from itself' #72715

Open
@karwa

Description

@karwa

Description

No response

Reproduction

final class C: C.Foo {
  class Foo {}
}
<source>:1:13: error: 'C' inherits from itself
1 │ final class C: C.Foo {
  │             │    ╰─ note: through reference here
  │             ├─ error: 'C' inherits from itself
  │             ╰─ note: through reference here
2 │   class Foo {}
3 │ }
Compiler returned: 1

Expected behavior

In the given example, C does not actually inherit from itself, so I think this should be allowed.

C.Foo is an independent type, which just so happens to be nested within C; in other words C.Foo is C would be false.

Environment

Swift version 6.0-dev (LLVM 87789f04c6598f1, Swift 52e8fbc)
Target: x86_64-unknown-linux-gnu

Additional information

Godbolt

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.classFeature → type declarations: Class declarationscompilerThe Swift compiler itselfdeclarationsFeature: declarationsinheritance clausesFeature → type declarations: Type inheritance clausesswift 6.0type checkerArea → compiler: Semantic analysistype declarationsFeature → declarations: Type declarationsunexpected errorBug: Unexpected error

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions