Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
hamishknight opened this issue Jun 29, 2018 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself inheritance Feature → type declarations → class: Subclassing and inheritance of class members not a bug Resolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer error protocol compositions Feature → types: protocol composition types type checker Area → compiler: Semantic analysis

Comments

@hamishknight
Copy link
Collaborator

hamishknight commented Jun 29, 2018

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'
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added inheritance Feature → type declarations → class: Subclassing and inheritance of class members protocol compositions Feature → types: protocol composition types type checker Area → compiler: Semantic analysis not a bug Resolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer error labels Dec 13, 2022
@AnthonyLatsis
Copy link
Collaborator

I believe this has become the expected behaviour by now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself inheritance Feature → type declarations → class: Subclassing and inheritance of class members not a bug Resolution → not a bug: Reported as a bug but turned out to be expected behavior or programmer error protocol compositions Feature → types: protocol composition types type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants