Skip to content

Commit 1b9d19a

Browse files
authored
Merge pull request #11243 from slavapestov/one-last-name-lookup-cleanup
One last name lookup cleanup
2 parents 1b18b82 + bfb252a commit 1b9d19a

File tree

3 files changed

+41
-49
lines changed

3 files changed

+41
-49
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3092,11 +3092,6 @@ performMemberLookup(ConstraintKind constraintKind, DeclName memberName,
30923092
if (includeInaccessibleMembers)
30933093
lookupOptions |= NameLookupFlags::IgnoreAccessibility;
30943094

3095-
// If a constructor is only visible as a witness for a protocol
3096-
// requirement, it must be an invalid override. Also, protocol
3097-
// extensions cannot yet define designated initializers.
3098-
lookupOptions -= NameLookupFlags::PerformConformanceCheck;
3099-
31003095
LookupResult ctors = TC.lookupConstructors(DC, instanceTy, lookupOptions);
31013096
if (!ctors)
31023097
return result; // No result.

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@ namespace {
129129

130130
assert(isa<ProtocolDecl>(foundDC));
131131

132+
if (!Options.contains(NameLookupFlags::PerformConformanceCheck))
133+
return;
134+
135+
// If we found something within the protocol itself, and our
136+
// search began somewhere that is not in a protocol or extension
137+
// thereof, remap this declaration to the witness.
132138
auto conformingType = foundInType;
133139

134140
// When performing a lookup on a subclass existential, we might
@@ -143,52 +149,43 @@ namespace {
143149
conformingType = layout.superclass;
144150
}
145151

146-
// If we found something within the protocol itself, and our
147-
// search began somewhere that is not in a protocol or extension
148-
// thereof, remap this declaration to the witness.
149-
if (foundInType->is<ArchetypeType>() ||
150-
foundInType->isExistentialType() ||
151-
Options.contains(NameLookupFlags::PerformConformanceCheck)) {
152-
// Dig out the protocol conformance.
153-
auto conformance = TC.conformsToProtocol(conformingType, foundProto, DC,
152+
// Dig out the protocol conformance.
153+
auto conformance = TC.conformsToProtocol(conformingType, foundProto, DC,
154154
conformanceOptions);
155-
if (!conformance) {
156-
// If there's no conformance, we have an existential
157-
// and we found a member from one of the protocols, and
158-
// not a class constraint if any.
159-
assert(foundInType->isExistentialType());
160-
addResult(found);
161-
return;
162-
}
163-
164-
if (conformance->isAbstract()) {
165-
assert(foundInType->is<ArchetypeType>() ||
166-
foundInType->isExistentialType());
167-
addResult(found);
168-
return;
169-
}
170-
171-
// Dig out the witness.
172-
ValueDecl *witness = nullptr;
173-
auto concrete = conformance->getConcrete();
174-
if (auto assocType = dyn_cast<AssociatedTypeDecl>(found)) {
175-
witness = concrete->getTypeWitnessAndDecl(assocType, &TC)
176-
.second;
177-
} else if (found->isProtocolRequirement()) {
178-
witness = concrete->getWitnessDecl(found, &TC);
179-
}
180-
181-
// FIXME: the "isa<ProtocolDecl>()" check will be wrong for
182-
// default implementations in protocols.
183-
//
184-
// If we have an imported conformance or the witness could
185-
// not be deserialized, getWitnessDecl() will just return
186-
// the requirement, so just drop the lookup result here.
187-
if (witness && !isa<ProtocolDecl>(witness->getDeclContext()))
188-
addResult(witness);
155+
if (!conformance) {
156+
// If there's no conformance, we have an existential
157+
// and we found a member from one of the protocols, and
158+
// not a class constraint if any.
159+
assert(foundInType->isExistentialType());
160+
addResult(found);
161+
return;
162+
}
189163

164+
if (conformance->isAbstract()) {
165+
assert(foundInType->is<ArchetypeType>() ||
166+
foundInType->isExistentialType());
167+
addResult(found);
190168
return;
191169
}
170+
171+
// Dig out the witness.
172+
ValueDecl *witness = nullptr;
173+
auto concrete = conformance->getConcrete();
174+
if (auto assocType = dyn_cast<AssociatedTypeDecl>(found)) {
175+
witness = concrete->getTypeWitnessAndDecl(assocType, &TC)
176+
.second;
177+
} else if (found->isProtocolRequirement()) {
178+
witness = concrete->getWitnessDecl(found, &TC);
179+
}
180+
181+
// FIXME: the "isa<ProtocolDecl>()" check will be wrong for
182+
// default implementations in protocols.
183+
//
184+
// If we have an imported conformance or the witness could
185+
// not be deserialized, getWitnessDecl() will just return
186+
// the requirement, so just drop the lookup result here.
187+
if (witness && !isa<ProtocolDecl>(witness->getDeclContext()))
188+
addResult(witness);
192189
}
193190
};
194191
} // end anonymous namespace

test/Sema/diag_invalid_synthesized_init_proto_conformance.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ class A : P { } // expected-error{{initializer requirement 'init()' can only be
88
// No further errors
99

1010
class B : A {
11-
init(x : Int) {} // expected-note {{'init(x:)' declared here}}
11+
init(x : Int) {}
1212
}
1313

1414
class C : B { }
1515

1616
class D : B {
1717
init() {
18-
super.init() // expected-error{{missing argument for parameter 'x' in call}}
18+
super.init()
1919
}
2020
}
2121

0 commit comments

Comments
 (0)