Skip to content

Commit f2536c2

Browse files
authored
Merge pull request #16585 from slavapestov/generic-type-alias-access-level-regression-4.2-30
Generic type alias access level regression [4.2 04/30/2018]
2 parents 7cf5e50 + c2153ff commit f2536c2

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

lib/AST/DeclContext.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,9 @@ IterableDeclContext::castDeclToIterableDeclContext(const Decl *D) {
821821
/// declaration or extension, the supplied context is returned.
822822
static const DeclContext *
823823
getPrivateDeclContext(const DeclContext *DC, const SourceFile *useSF) {
824+
if (DC->getASTContext().isSwiftVersion3())
825+
return DC;
826+
824827
auto NTD = DC->getAsNominalTypeOrNominalTypeExtensionContext();
825828
if (!NTD)
826829
return DC;

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,8 +1408,7 @@ class TypeAccessScopeChecker : private TypeWalker, AccessScopeChecker {
14081408
return Action::Stop;
14091409

14101410
if (!CanonicalizeParentTypes) {
1411-
return isa<NameAliasType>(T.getPointer()) ? Action::SkipChildren
1412-
: Action::Continue;
1411+
return Action::Continue;
14131412
}
14141413

14151414
Type nominalParentTy;

test/Compatibility/accessibility_private.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@ extension Container {
171171
extension Container {
172172
private struct VeryPrivateStruct { // expected-note * {{type declared here}}
173173
private typealias VeryPrivateType = Int // expected-note * {{type declared here}}
174+
private struct VeryPrivateInnerStruct {}
174175
var privateVar: VeryPrivateType { fatalError() } // expected-warning {{property should be declared private because its type uses a private type}}
175176
var privateVar2 = VeryPrivateType() // expected-warning {{property should be declared private because its type 'Container.VeryPrivateStruct.VeryPrivateType' (aka 'Int') uses a private type}}
177+
var privateVar3 = VeryPrivateInnerStruct() // expected-warning {{property should be declared private because its type 'Container.VeryPrivateStruct.VeryPrivateInnerStruct' uses a private type}}
176178
typealias PrivateAlias = VeryPrivateType // expected-warning {{type alias should be declared private because its underlying type uses a private type}}
177179
subscript(_: VeryPrivateType) -> Void { return () } // expected-warning {{subscript should be declared private because its index uses a private type}}
178180
func privateMethod(_: VeryPrivateType) -> Void {} // expected-warning {{method should be declared private because its parameter uses a private type}} {{none}}

test/Sema/accessibility_private.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,10 @@ extension Container {
171171
extension Container {
172172
private struct VeryPrivateStruct { // expected-note * {{type declared here}}
173173
private typealias VeryPrivateType = Int // expected-note * {{type declared here}}
174+
private struct VeryPrivateInnerStruct {}
174175
var privateVar: VeryPrivateType { fatalError() } // expected-error {{property must be declared private because its type uses a private type}}
175176
var privateVar2 = VeryPrivateType() // expected-error {{property must be declared private because its type 'Container.VeryPrivateStruct.VeryPrivateType' (aka 'Int') uses a private type}}
177+
var privateVar3 = VeryPrivateInnerStruct() // expected-error {{property must be declared private because its type 'Container.VeryPrivateStruct.VeryPrivateInnerStruct' uses a private type}}
176178
typealias PrivateAlias = VeryPrivateType // expected-error {{type alias must be declared private because its underlying type uses a private type}}
177179
subscript(_: VeryPrivateType) -> Void { return () } // expected-error {{subscript must be declared private because its index uses a private type}}
178180
func privateMethod(_: VeryPrivateType) -> Void {} // expected-error {{method must be declared private because its parameter uses a private type}} {{none}}

test/Sema/accessibility_typealias.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,13 @@ public var failNested2: (_ x: (main.ActuallyPrivate) -> Void) -> Void = { _ in }
9090
public func failTest(x: ActuallyPrivate) {} // expected-error {{cannot be declared public}}
9191
public func failTest2(x: main.ActuallyPrivate) {} // expected-error {{cannot be declared public}}
9292

93+
// Property has an inferred type, public alias with
94+
// private generic parameter bound.
95+
public struct PublicGeneric<T> {}
96+
97+
public typealias GenericAlias<T> = PublicGeneric<T>
98+
99+
fileprivate func makeAValue() -> GenericAlias<ActuallyPrivate> { }
100+
101+
public var cannotBePublic = makeAValue()
102+
// expected-error@-1 {{variable cannot be declared public because its type 'GenericAlias<ActuallyPrivate>' (aka 'PublicGeneric<ActuallyPrivate>') uses a private type}}

0 commit comments

Comments
 (0)