Skip to content

Commit 253bd10

Browse files
committed
Cope with BoundNameAliasType in more places that handle NameAliasType.
1 parent e6c91b3 commit 253bd10

File tree

7 files changed

+36
-4
lines changed

7 files changed

+36
-4
lines changed

lib/AST/Type.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3964,6 +3964,21 @@ bool Type::isPrivateStdlibType(bool treatNonBuiltinProtocolsAsPublic) const {
39643964
return AliasDecl->isPrivateStdlibDecl(treatNonBuiltinProtocolsAsPublic);
39653965
}
39663966

3967+
// A 'public' typealias can have an 'internal' type.
3968+
if (auto *BNAT = dyn_cast<BoundNameAliasType>(Ty.getPointer())) {
3969+
auto *AliasDecl = BNAT->getDecl();
3970+
if (auto parent = BNAT->getParent()) {
3971+
if (parent.isPrivateStdlibType(treatNonBuiltinProtocolsAsPublic))
3972+
return true;
3973+
}
3974+
3975+
if (AliasDecl->isPrivateStdlibDecl(treatNonBuiltinProtocolsAsPublic))
3976+
return true;
3977+
3978+
return Type(BNAT->getSinglyDesugaredType()).isPrivateStdlibType(
3979+
treatNonBuiltinProtocolsAsPublic);
3980+
}
3981+
39673982
if (auto Paren = dyn_cast<ParenType>(Ty.getPointer())) {
39683983
Type Underlying = Paren->getUnderlyingType();
39693984
return Underlying.isPrivateStdlibType(treatNonBuiltinProtocolsAsPublic);

lib/IRGen/DebugTypeInfo.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ TypeDecl *DebugTypeInfo::getDecl() const {
147147
return N->getDecl();
148148
if (auto *TA = dyn_cast<NameAliasType>(Type))
149149
return TA->getDecl();
150+
if (auto *BTA = dyn_cast<BoundNameAliasType>(Type))
151+
return BTA->getDecl();
150152
if (auto *UBG = dyn_cast<UnboundGenericType>(Type))
151153
return UBG->getDecl();
152154
if (auto *BG = dyn_cast<BoundGenericType>(Type))

lib/Sema/MiscDiagnostics.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3838,6 +3838,11 @@ static OmissionTypeName getTypeNameForOmission(Type type) {
38383838
continue;
38393839
}
38403840

3841+
if (auto boundAliasTy = dyn_cast<BoundNameAliasType>(type.getPointer())) {
3842+
type = boundAliasTy->getSinglyDesugaredType();
3843+
continue;
3844+
}
3845+
38413846
// Strip off lvalue/inout types.
38423847
Type newType = type->getWithoutSpecifierType();
38433848
if (newType.getPointer() != type.getPointer()) {

lib/Sema/TypeCheckExpr.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,9 @@ Type TypeChecker::getDefaultType(ProtocolDecl *protocol, DeclContext *dc) {
660660
if (type && *type) {
661661
if (auto typeAlias = dyn_cast<NameAliasType>(type->getPointer()))
662662
*type = typeAlias->getSinglyDesugaredType();
663+
else if (auto boundTypeAlias =
664+
dyn_cast<BoundNameAliasType>(type->getPointer()))
665+
*type = boundTypeAlias->getSinglyDesugaredType();
663666
}
664667
}
665668

test/Sema/accessibility_typealias.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ public final class ReplayableGenerator<S: Sequence> : IteratorProtocol {
2626
}
2727
}
2828

29-
// FIXME: Dependent member lookup of typealiases is not subject
30-
// to accessibility checking.
3129
struct Generic<T> {
3230
fileprivate typealias Dependent = T
3331
}
@@ -42,8 +40,7 @@ private func privateFuncWithFileprivateAlias() -> Generic<Int>.Dependent {
4240
return 3
4341
}
4442

45-
// FIXME: No error here
46-
var y = privateFuncWithFileprivateAlias()
43+
var y = privateFuncWithFileprivateAlias() // expected-error{{variable must be declared private or fileprivate because its type 'Generic<Int>.Dependent' (aka 'Int') uses a fileprivate type}}
4744

4845

4946
private typealias FnType = (_ x: Int) -> Void // expected-note * {{type declared here}}

tools/SourceKit/lib/SwiftLang/SwiftDocSupport.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ static bool initDocEntityInfo(const TextEntity &Entity,
457457
static const TypeDecl *getTypeDeclFromType(Type Ty) {
458458
if (auto Alias = dyn_cast<NameAliasType>(Ty.getPointer()))
459459
return Alias->getDecl();
460+
if (auto BoundAlias = dyn_cast<BoundNameAliasType>(Ty.getPointer()))
461+
return BoundAlias->getDecl();
460462
return Ty->getAnyNominal();
461463
}
462464

tools/swift-api-digester/swift-api-digester.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,6 +1158,9 @@ static StringRef getTypeName(SDKContext &Ctx, Type Ty,
11581158
if (auto *NAT = dyn_cast<NameAliasType>(Ty.getPointer())) {
11591159
return NAT->getDecl()->getNameStr();
11601160
}
1161+
if (auto *BNAT = dyn_cast<BoundNameAliasType>(Ty.getPointer())) {
1162+
return BNAT->getDecl()->getNameStr();
1163+
}
11611164
if (Ty->getAnyNominal()) {
11621165
if (IsImplicitlyUnwrappedOptional) {
11631166
assert(Ty->getOptionalObjectType());
@@ -1360,6 +1363,11 @@ static SDKNode *constructTypeNode(SDKContext &Ctx, Type T,
13601363
Root->addChild(constructTypeNode(Ctx, NAT->getCanonicalType()));
13611364
return Root;
13621365
}
1366+
if (auto BNAT = dyn_cast<BoundNameAliasType>(T.getPointer())) {
1367+
SDKNode* Root = SDKNodeInitInfo(Ctx, T).createSDKNode(SDKNodeKind::TypeNameAlias);
1368+
Root->addChild(constructTypeNode(Ctx, BNAT->getCanonicalType()));
1369+
return Root;
1370+
}
13631371

13641372
if (auto Fun = T->getAs<AnyFunctionType>()) {
13651373
SDKNode* Root = SDKNodeInitInfo(Ctx, T).createSDKNode(SDKNodeKind::TypeFunc);

0 commit comments

Comments
 (0)