Skip to content

Sema: Name lookup of protocol typealiases from expression context #12436

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
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
1 change: 1 addition & 0 deletions lib/Sema/TypeCheckNameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ namespace {
if (!Options.contains(NameLookupFlags::ProtocolMembers) ||
!isa<ProtocolDecl>(foundDC) ||
isa<GenericTypeParamDecl>(found) ||
isa<TypeAliasDecl>(found) ||
(isa<FuncDecl>(found) && cast<FuncDecl>(found)->isOperator())) {
addResult(found);
return;
Expand Down
16 changes: 8 additions & 8 deletions test/decl/typealias/generic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -338,10 +338,10 @@ class AnotherGeneric<T> {}

protocol P {
associatedtype A
typealias G1<T> = MyType<Self, T> // expected-note {{did you mean 'G1'?}}
typealias G2<T> = MyType<T, A> // expected-note {{did you mean 'G2'?}}
typealias G3<T> = () -> () // expected-note {{did you mean 'G3'?}}
typealias G4<T> = (T) -> () // expected-note {{did you mean 'G4'?}}
typealias G1<T> = MyType<Self, T>
typealias G2<T> = MyType<T, A>
typealias G3<T> = () -> ()
typealias G4<T> = (T) -> ()

func firstRequirement(_: G1<Int>)
func secondRequirement(_: G2<Int>)
Expand All @@ -368,19 +368,19 @@ struct S : P {
func fourthRequirement(_: G4<Int>) {}

func firstRequirementGeneric<T>(_: G1<T>) {
_ = G1<T>.self // FIXME // expected-error {{use of unresolved identifier 'G1'}}
_ = G1<T>.self
}

func secondRequirementGeneric<T>(_: G2<T>) {
_ = G2<T>.self // FIXME // expected-error {{use of unresolved identifier 'G2'}}
_ = G2<T>.self
}

func thirdRequirementGeneric<T>(_: G3<T>, _: T) {
_ = G3<T>.self // FIXME // expected-error {{use of unresolved identifier 'G3'}}
_ = G3<T>.self
}

func fourthRequirementGeneric<T>(_: G4<T>) {
_ = G4<T>.self // FIXME // expected-error {{use of unresolved identifier 'G4'}}
_ = G4<T>.self
}

func expressionContext() {
Expand Down
2 changes: 2 additions & 0 deletions test/decl/typealias/protocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ struct T5 : P5 {
// Unqualified lookup finds typealiases in protocol extensions
protocol P7 {
associatedtype A
typealias Z = A
}

extension P7 {
Expand All @@ -203,6 +204,7 @@ struct S7 : P7 {

func inExpressionContext() {
_ = Y.self
_ = Z.self
_ = T5.T1.self
_ = T5.T2.self
}
Expand Down