diff --git a/lib/AST/DeclContext.cpp b/lib/AST/DeclContext.cpp index 3ee8f65ec0743..f4861fc895077 100644 --- a/lib/AST/DeclContext.cpp +++ b/lib/AST/DeclContext.cpp @@ -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; diff --git a/lib/Sema/TypeCheckDecl.cpp b/lib/Sema/TypeCheckDecl.cpp index f42f22a3c1cfc..8f338b33a46fb 100644 --- a/lib/Sema/TypeCheckDecl.cpp +++ b/lib/Sema/TypeCheckDecl.cpp @@ -1408,8 +1408,7 @@ class TypeAccessScopeChecker : private TypeWalker, AccessScopeChecker { return Action::Stop; if (!CanonicalizeParentTypes) { - return isa(T.getPointer()) ? Action::SkipChildren - : Action::Continue; + return Action::Continue; } Type nominalParentTy; diff --git a/test/Compatibility/accessibility_private.swift b/test/Compatibility/accessibility_private.swift index d234ea32d08e7..1d26677c98eea 100644 --- a/test/Compatibility/accessibility_private.swift +++ b/test/Compatibility/accessibility_private.swift @@ -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}} diff --git a/test/Sema/accessibility_private.swift b/test/Sema/accessibility_private.swift index d5110be66ce87..16d47986a6c2d 100644 --- a/test/Sema/accessibility_private.swift +++ b/test/Sema/accessibility_private.swift @@ -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}} diff --git a/test/Sema/accessibility_typealias.swift b/test/Sema/accessibility_typealias.swift index e9373b892a7a5..6e7cac2ccaabb 100644 --- a/test/Sema/accessibility_typealias.swift +++ b/test/Sema/accessibility_typealias.swift @@ -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 {} + +public typealias GenericAlias = PublicGeneric + +fileprivate func makeAValue() -> GenericAlias { } + +public var cannotBePublic = makeAValue() +// expected-error@-1 {{variable cannot be declared public because its type 'GenericAlias' (aka 'PublicGeneric') uses a private type}}