Skip to content

Fix two issues with typealiases in protocol extensions #20654

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
merged 1 commit into from
Nov 26, 2018
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
4 changes: 1 addition & 3 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2119,9 +2119,7 @@ TypeDecl *EquivalenceClass::lookupNestedType(
ProtocolDecl *proto = conforms.first;

// Look for an associated type and/or concrete type with this name.
auto flags = OptionSet<NominalTypeDecl::LookupDirectFlags>();
flags |= NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions;
for (auto member : proto->lookupDirect(name, flags)) {
for (auto member : proto->lookupDirect(name)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to see this worked without any fallout!

// If this is an associated type, record whether it is the best
// associated type we've seen thus far.
if (auto assocType = dyn_cast<AssociatedTypeDecl>(member)) {
Expand Down
9 changes: 4 additions & 5 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1406,9 +1406,9 @@ ModuleFile::resolveCrossReference(ModuleDecl *baseModule, uint32_t pathLen) {
IdentifierID IID;
IdentifierID privateDiscriminator;
bool importedFromClang = false;
bool inProtocolExt = false;
XRefTypePathPieceLayout::readRecord(scratch, IID, privateDiscriminator,
/*inProtocolExt*/None,
importedFromClang);
inProtocolExt, importedFromClang);
if (privateDiscriminator)
goto giveUpFastPath;

Expand Down Expand Up @@ -1438,9 +1438,8 @@ ModuleFile::resolveCrossReference(ModuleDecl *baseModule, uint32_t pathLen) {
if (nestedType) {
SmallVector<ValueDecl *, 1> singleValueBuffer{nestedType};
filterValues(/*expectedTy*/Type(), extensionModule, genericSig,
/*isType*/true, /*inProtocolExt*/false,
importedFromClang, /*isStatic*/false, /*ctorInit*/None,
singleValueBuffer);
/*isType*/true, inProtocolExt, importedFromClang,
/*isStatic*/false, /*ctorInit*/None, singleValueBuffer);
if (!singleValueBuffer.empty()) {
values.assign({nestedType});
++NumNestedTypeShortcuts;
Expand Down
4 changes: 3 additions & 1 deletion lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1877,10 +1877,12 @@ void Serializer::writeCrossReference(const DeclContext *DC, uint32_t pathLen) {
discriminator = containingFile->getDiscriminatorForPrivateValue(generic);
}

bool isProtocolExt = DC->getParent()->getExtendedProtocolDecl();

XRefTypePathPieceLayout::emitRecord(Out, ScratchRecord, abbrCode,
addDeclBaseNameRef(generic->getName()),
addDeclBaseNameRef(discriminator),
/*inProtocolExtension*/false,
isProtocolExt,
generic->hasClangNode());
break;
}
Expand Down
6 changes: 6 additions & 0 deletions test/multifile/typealias/one-module/Inputs/library.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ public enum Result<T, U>
}

public typealias GenericResult<T> = Result<T, Error>

public protocol Rdar46103190 {}
extension Rdar46103190 {
public typealias Alias = String
public typealias Map<K: Hashable> = [K: Self]
}
15 changes: 15 additions & 0 deletions test/multifile/typealias/one-module/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,18 @@

func testFunction<T>(withCompletion completion: (Result<T, Error>) -> Void) { }
testFunction { (result: GenericResult<Int>) in }

extension Rdar46103190 {
public typealias AnotherAlias = Self.Alias
public typealias StringMap = Map<String>
}

typealias Rdar46103190Alias<R: Rdar46103190> = R.Map<String>

struct Rdar46103190Impl: Rdar46103190 {}

func test46103190() {
let _: String = Rdar46103190Impl.AnotherAlias()
let _: [String: Rdar46103190Impl] = Rdar46103190Impl.StringMap()
let _: [String: Rdar46103190Impl] = Rdar46103190Alias()
}
6 changes: 6 additions & 0 deletions test/multifile/typealias/two-modules/Inputs/library.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@ public enum Result<T, U>
}

public typealias GenericResult<T> = Result<T, Error>

public protocol Rdar46103190 {}
extension Rdar46103190 {
public typealias Alias = String
public typealias Map<K: Hashable> = [K: Self]
}
15 changes: 15 additions & 0 deletions test/multifile/typealias/two-modules/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,18 @@ import library

func testFunction<T>(withCompletion completion: (Result<T, Error>) -> Void) { }
testFunction { (result: GenericResult<Int>) in }

extension Rdar46103190 {
public typealias AnotherAlias = Self.Alias
public typealias StringMap = Map<String>
}

typealias Rdar46103190Alias<R: Rdar46103190> = R.Map<String>

struct Rdar46103190Impl: Rdar46103190 {}

func test46103190() {
let _: String = Rdar46103190Impl.AnotherAlias()
let _: [String: Rdar46103190Impl] = Rdar46103190Impl.StringMap()
let _: [String: Rdar46103190Impl] = Rdar46103190Alias()
}