Skip to content

AST: Fix ProtocolDecl::getInheritedProtocols() for protocols that inherit from compositions [4.0] #10354

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2905,10 +2905,13 @@ ProtocolDecl::getInheritedProtocols() const {
// Only protocols can appear in the inheritance clause
// of a protocol -- anything else should get diagnosed
// elsewhere.
if (auto *protoTy = type->getAs<ProtocolType>()) {
auto *protoDecl = protoTy->getDecl();
if (known.insert(protoDecl).second)
result.push_back(protoDecl);
if (type->isExistentialType()) {
auto layout = type->getExistentialLayout();
for (auto protoTy : layout.getProtocols()) {
auto *protoDecl = protoTy->getDecl();
if (known.insert(protoDecl).second)
result.push_back(protoDecl);
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/NameBinding/Inputs/protocol-inheritance.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
public protocol Critter {
associatedtype Fur
}
public protocol Pet {}

public typealias Cat = Critter & Pet

public protocol Kitten : Cat {}

extension Kitten {
public func pet() -> Fur {
while true {}
}
}

public final class Meow<Purrs> : Kitten {
public typealias Fur = Purrs
}
5 changes: 5 additions & 0 deletions test/NameBinding/protocol-inheritance.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: %target-swift-frontend -typecheck -primary-file %s %S/Inputs/protocol-inheritance.swift

func kitty<Purrs>(cat: Meow<Purrs>) {
cat.pet()
}