Skip to content

[SR-8151] Class inheriting from class existential behaviour doesn't match SE-0156 #50683

@hamishknight

Description

@hamishknight
Previous ID SR-8151
Radar None
Original Reporter @hamishknight
Type Bug
Environment

Apple Swift version 4.2-dev (LLVM 9d4565013d, Clang f12d22bf9f, Swift 6982d65)
Target: x86_64-apple-darwin17.6.0

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: ee8dafed896ec4393455a7ad1df822bc

relates to:

  • SR-7405 Protocol compositions: improve composing diagnostics

Issue Description:

In SE-0156, the following rule is given:

To improve readability and reduce confusion, a class conforming to a typealias which contains a class type constraint does not implicitly inherit the class type: inheritance should stay explicit. Here are a few examples to remind what the current rules are and to make the previous sentence clearer:

The proposal does not change the rule which forbids using the protocol composition syntax in the inheritance clause:

protocol P1 {}
protocol P2 {}
class C {}
class D : P1 & P2 {} // Compiler error
class E : C & P1 {} // Compiler error

Class D in the previous example does not inherit a base class so it can be expressed using the inheritance/conformance syntax or through a typealias:

class D : P1, P2 {} // Valid
typealias P12 = P1 & P2
class D : P12 {} // Valid

Class E above inherits a base class. The inheritance must be explicitly declared in the inheritance clause and can't be implicitly derived from a typealias:

class E : C, P1 {} // Valid
typealias CP1 = C & P1
class E : CP1 {} // Compiler error: class 'E' does not inherit from class 'C'
class E : C, CP1 {} // Valid: the inheritance is explicitly declared

However this rule doesn't appear to match the current implementation. The following doesn't yield a compiler error, despite the proposal saying the inheritance must be spelled explicitly:

protocol P1 {}
protocol P2 {}
class C {}
typealias CP1 = C & P1
class E : CP1 {}

and the following doesn't compile, despite the proposal saying that it should:

protocol P1 {}
protocol P2 {}
class C {}
typealias CP1 = C & P1
class E : C, CP1 {} // error: Multiple inheritance from classes 'C' and 'C'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfinheritanceFeature → type declarations → class: Subclassing and inheritance of class membersnot a bugResolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer errorprotocol compositionsFeature → types: protocol composition typestype checkerArea → compiler: Semantic analysis

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions