Skip to content

Generic type alias access level regression [4.2 04/30/2018] #16585

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
3 changes: 3 additions & 0 deletions lib/AST/DeclContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,9 @@ IterableDeclContext::castDeclToIterableDeclContext(const Decl *D) {
/// declaration or extension, the supplied context is returned.
static const DeclContext *
getPrivateDeclContext(const DeclContext *DC, const SourceFile *useSF) {
if (DC->getASTContext().isSwiftVersion3())
return DC;

auto NTD = DC->getAsNominalTypeOrNominalTypeExtensionContext();
if (!NTD)
return DC;
Expand Down
3 changes: 1 addition & 2 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1408,8 +1408,7 @@ class TypeAccessScopeChecker : private TypeWalker, AccessScopeChecker {
return Action::Stop;

if (!CanonicalizeParentTypes) {
return isa<NameAliasType>(T.getPointer()) ? Action::SkipChildren
: Action::Continue;
return Action::Continue;
}

Type nominalParentTy;
Expand Down
2 changes: 2 additions & 0 deletions test/Compatibility/accessibility_private.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ extension Container {
extension Container {
private struct VeryPrivateStruct { // expected-note * {{type declared here}}
private typealias VeryPrivateType = Int // expected-note * {{type declared here}}
private struct VeryPrivateInnerStruct {}
var privateVar: VeryPrivateType { fatalError() } // expected-warning {{property should be declared private because its type uses a private type}}
var privateVar2 = VeryPrivateType() // expected-warning {{property should be declared private because its type 'Container.VeryPrivateStruct.VeryPrivateType' (aka 'Int') uses a private type}}
var privateVar3 = VeryPrivateInnerStruct() // expected-warning {{property should be declared private because its type 'Container.VeryPrivateStruct.VeryPrivateInnerStruct' uses a private type}}
typealias PrivateAlias = VeryPrivateType // expected-warning {{type alias should be declared private because its underlying type uses a private type}}
subscript(_: VeryPrivateType) -> Void { return () } // expected-warning {{subscript should be declared private because its index uses a private type}}
func privateMethod(_: VeryPrivateType) -> Void {} // expected-warning {{method should be declared private because its parameter uses a private type}} {{none}}
Expand Down
2 changes: 2 additions & 0 deletions test/Sema/accessibility_private.swift
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,10 @@ extension Container {
extension Container {
private struct VeryPrivateStruct { // expected-note * {{type declared here}}
private typealias VeryPrivateType = Int // expected-note * {{type declared here}}
private struct VeryPrivateInnerStruct {}
var privateVar: VeryPrivateType { fatalError() } // expected-error {{property must be declared private because its type uses a private type}}
var privateVar2 = VeryPrivateType() // expected-error {{property must be declared private because its type 'Container.VeryPrivateStruct.VeryPrivateType' (aka 'Int') uses a private type}}
var privateVar3 = VeryPrivateInnerStruct() // expected-error {{property must be declared private because its type 'Container.VeryPrivateStruct.VeryPrivateInnerStruct' uses a private type}}
typealias PrivateAlias = VeryPrivateType // expected-error {{type alias must be declared private because its underlying type uses a private type}}
subscript(_: VeryPrivateType) -> Void { return () } // expected-error {{subscript must be declared private because its index uses a private type}}
func privateMethod(_: VeryPrivateType) -> Void {} // expected-error {{method must be declared private because its parameter uses a private type}} {{none}}
Expand Down
10 changes: 10 additions & 0 deletions test/Sema/accessibility_typealias.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,13 @@ public var failNested2: (_ x: (main.ActuallyPrivate) -> Void) -> Void = { _ in }
public func failTest(x: ActuallyPrivate) {} // expected-error {{cannot be declared public}}
public func failTest2(x: main.ActuallyPrivate) {} // expected-error {{cannot be declared public}}

// Property has an inferred type, public alias with
// private generic parameter bound.
public struct PublicGeneric<T> {}

public typealias GenericAlias<T> = PublicGeneric<T>

fileprivate func makeAValue() -> GenericAlias<ActuallyPrivate> { }

public var cannotBePublic = makeAValue()
// expected-error@-1 {{variable cannot be declared public because its type 'GenericAlias<ActuallyPrivate>' (aka 'PublicGeneric<ActuallyPrivate>') uses a private type}}