Skip to content

Commit facfb61

Browse files
committed
Sema: Fix access control regression with generic type aliases
If a property had an inferred type that is a generic type alias, we weren't checking the access level of the generic arguments. This used to work in 4.1 because we didn't have a sugared representation for generic type aliases, so we were checking the substituted underlying type here. But now that NameAliasType can store generic arguments, make sure we visit them here. Fixes <rdar://problem/40188409>.
1 parent 0957f85 commit facfb61

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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/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)