Uploaded image for project: 'Swift'
  1. Swift
  2. SR-8151

Class inheriting from class existential behaviour doesn't match SE-0156

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Medium
    • Resolution: Unresolved
    • Component/s: Compiler
    • Labels:
      None
    • Environment:

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

      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'
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned
              Reporter:
              originaluser2 Hamish Knight
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated: