Skip to content

Remove a too-strict assertion concerning nested protocols #18241

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
merged 1 commit into from
Jul 26, 2018
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: 4 additions & 7 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2504,13 +2504,10 @@ static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
// marked 'public' if the protocol was '@_versioned' (now
// '@usableFromInline'). Which works at the ABI level, so let's keep
// supporting that here by explicitly checking for it.
if (access == AccessLevel::Public) {
assert(proto->getDeclContext()->isModuleScopeContext() &&
"if we get nested protocols, this should not apply to them");
if (proto->getFormalAccess() == AccessLevel::Internal &&
proto->isUsableFromInline()) {
return true;
}
if (access == AccessLevel::Public &&
proto->getFormalAccess() == AccessLevel::Internal &&
proto->isUsableFromInline()) {
return true;
}

// Skip the fast path below and just compare access scopes.
Expand Down
20 changes: 20 additions & 0 deletions test/decl/nested/protocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,23 @@ struct Outer {
}
}
}

struct OuterForUFI {
@usableFromInline
protocol Inner { // expected-error {{protocol 'Inner' cannot be nested inside another declaration}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/me shudders when he sees test case

func req()
}
}

extension OuterForUFI.Inner {
public func extMethod() {} // The 'public' puts this in a special path.
}

func testLookup(_ x: OuterForUFI.Inner) {
x.req()
x.extMethod()
}
func testLookup<T: OuterForUFI.Inner>(_ x: T) {
x.req()
x.extMethod()
}