Skip to content

Commit 8b9d527

Browse files
committed
Sema: Don't assume ConformanceChecker::Adoptee is a nominal type
For tuple conformances, it will be the tuple type (T...).
1 parent ad31fa3 commit 8b9d527

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

lib/Sema/TypeCheckProtocol.cpp

+17-18
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ WitnessChecker::lookupValueWitnessesViaImplementsAttr(
12831283
ValueDecl *req, SmallVector<ValueDecl *, 4> &witnesses) {
12841284

12851285
auto name = req->createNameRef();
1286-
auto *nominal = Adoptee->getAnyNominal();
1286+
auto *nominal = DC->getSelfNominalTypeDecl();
12871287

12881288
NLOptions subOptions = (NL_ProtocolMembers | NL_IncludeAttributeImplements);
12891289

@@ -1338,7 +1338,7 @@ WitnessChecker::lookupValueWitnesses(ValueDecl *req, bool *ignoringNames) {
13381338
}
13391339

13401340
if (doQualifiedLookup) {
1341-
auto *nominal = Adoptee->getAnyNominal();
1341+
auto *nominal = DC->getSelfNominalTypeDecl();
13421342
nominal->synthesizeSemanticMembersIfNeeded(reqName.getFullName());
13431343

13441344
// Unqualified lookup would have already found candidates from protocol
@@ -1551,7 +1551,7 @@ AccessScope WitnessChecker::getRequiredAccessScope() {
15511551

15521552
bool witnessesMustBeUsableFromInline = false;
15531553
if (Adoptee) {
1554-
const NominalTypeDecl *adoptingNominal = Adoptee->getAnyNominal();
1554+
const NominalTypeDecl *adoptingNominal = DC->getSelfNominalTypeDecl();
15551555

15561556
// Compute the intersection of the conforming type's access scope
15571557
// and the protocol's access scope.
@@ -2012,7 +2012,6 @@ checkIndividualConformance(NormalProtocolConformance *conformance,
20122012

20132013
// Dig out some of the fields from the conformance.
20142014
Type T = conformance->getType();
2015-
auto canT = T->getCanonicalType();
20162015
DeclContext *DC = conformance->getDeclContext();
20172016
auto Proto = conformance->getProtocol();
20182017
auto ProtoType = Proto->getDeclaredInterfaceType();
@@ -2030,7 +2029,7 @@ checkIndividualConformance(NormalProtocolConformance *conformance,
20302029
}
20312030

20322031
// If the protocol requires a class, non-classes are a non-starter.
2033-
if (Proto->requiresClass() && !canT->getClassOrBoundGenericClass()) {
2032+
if (Proto->requiresClass() && !DC->getSelfClassDecl()) {
20342033
C.Diags.diagnose(ComplainLoc,
20352034
diag::non_class_cannot_conform_to_class_protocol, T,
20362035
ProtoType);
@@ -2060,7 +2059,7 @@ checkIndividualConformance(NormalProtocolConformance *conformance,
20602059

20612060
if (Proto->isObjC()) {
20622061
// Foreign classes cannot conform to objc protocols.
2063-
if (auto clazz = canT->getClassOrBoundGenericClass()) {
2062+
if (auto clazz = DC->getSelfClassDecl()) {
20642063
Optional<decltype(diag::cf_class_cannot_conform_to_objc_protocol)>
20652064
diagKind;
20662065
switch (clazz->getForeignClassKind()) {
@@ -2114,7 +2113,7 @@ checkIndividualConformance(NormalProtocolConformance *conformance,
21142113
// Not every protocol/type is compatible with conditional conformances.
21152114
auto conditionalReqs = conformance->getConditionalRequirementsIfAvailable();
21162115
if (conditionalReqs && !conditionalReqs->empty()) {
2117-
auto nestedType = canT;
2116+
auto nestedType = DC->getSelfNominalTypeDecl()->getDeclaredInterfaceType();
21182117
// Obj-C generics cannot be looked up at runtime, so we don't support
21192118
// conditional conformances involving them. Check the full stack of nested
21202119
// types for any obj-c ones.
@@ -2129,7 +2128,7 @@ checkIndividualConformance(NormalProtocolConformance *conformance,
21292128
}
21302129
}
21312130

2132-
nestedType = nestedType.getNominalParent();
2131+
nestedType = nestedType->getNominalParent();
21332132
}
21342133

21352134
// If the protocol to which we are conditionally conforming is not a marker
@@ -3212,7 +3211,7 @@ bool ConformanceChecker::checkObjCTypeErasedGenerics(
32123211
if (!ctx.LangOpts.EnableObjCInterop && type->hasError())
32133212
return false;
32143213

3215-
auto classDecl = Adoptee->getClassOrBoundGenericClass();
3214+
auto classDecl = DC->getSelfClassDecl();
32163215
if (!classDecl) return false;
32173216

32183217
if (!classDecl->isTypeErasedGenericClass()) return false;
@@ -3784,7 +3783,7 @@ diagnoseMissingWitnesses(MissingWitnessDiagnosisKind Kind) {
37843783
for (auto &Missing : LocalMissing) {
37853784
auto requirement = Missing.requirement;
37863785
auto matches = Missing.matches;
3787-
auto nominal = Adoptee->getAnyNominal();
3786+
auto nominal = DC->getSelfNominalTypeDecl();
37883787

37893788
diagnoseOrDefer(requirement, true,
37903789
[requirement, matches, nominal](NormalProtocolConformance *conformance) {
@@ -4014,7 +4013,7 @@ getAdopteeSelfSameTypeConstraint(ClassDecl *selfClass, ValueDecl *witness) {
40144013

40154014
void ConformanceChecker::checkNonFinalClassWitness(ValueDecl *requirement,
40164015
ValueDecl *witness) {
4017-
auto *classDecl = Adoptee->getClassOrBoundGenericClass();
4016+
auto *classDecl = DC->getSelfClassDecl();
40184017

40194018
// If we have an initializer requirement and the conforming type
40204019
// is a non-final class, the witness must be 'required'.
@@ -4161,7 +4160,7 @@ void ConformanceChecker::checkNonFinalClassWitness(ValueDecl *requirement,
41614160
ResolveWitnessResult
41624161
ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
41634162
assert(!isa<AssociatedTypeDecl>(requirement) && "Use resolveTypeWitnessVia*");
4164-
auto *nominal = Adoptee->getAnyNominal();
4163+
auto *nominal = DC->getSelfNominalTypeDecl();
41654164

41664165
// Resolve all associated types before trying to resolve this witness.
41674166
resolveTypeWitnesses();
@@ -4435,7 +4434,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
44354434
break;
44364435
}
44374436

4438-
if (auto *classDecl = Adoptee->getClassOrBoundGenericClass()) {
4437+
if (auto *classDecl = DC->getSelfClassDecl()) {
44394438
if (!classDecl->isSemanticallyFinal()) {
44404439
checkNonFinalClassWitness(requirement, witness);
44414440
}
@@ -4519,7 +4518,7 @@ ResolveWitnessResult ConformanceChecker::resolveWitnessViaDerivation(
45194518

45204519
// Find the declaration that derives the protocol conformance.
45214520
NominalTypeDecl *derivingTypeDecl = nullptr;
4522-
auto *nominal = Adoptee->getAnyNominal();
4521+
auto *nominal = DC->getSelfNominalTypeDecl();
45234522
if (DerivedConformance::derivesProtocolConformance(DC, nominal, Proto))
45244523
derivingTypeDecl = nominal;
45254524

@@ -4694,7 +4693,7 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
46944693
// Look for a member type with the same name as the associated type.
46954694
SmallVector<ValueDecl *, 4> candidates;
46964695

4697-
DC->lookupQualified(Adoptee->getAnyNominal(),
4696+
DC->lookupQualified(DC->getSelfNominalTypeDecl(),
46984697
assocType->createNameRef(),
46994698
subOptions, candidates);
47004699

@@ -4734,7 +4733,7 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
47344733
if (typeAliasDecl->getUnderlyingType()->isNever()) {
47354734
if (typeAliasDecl->getParentModule()->getName().is("SwiftUI")) {
47364735
if (typeAliasDecl->getDeclContext()->getSelfNominalTypeDecl() ==
4737-
Adoptee->getAnyNominal()) {
4736+
DC->getSelfNominalTypeDecl()) {
47384737
const auto reqs =
47394738
typeAliasDecl->getGenericSignature().requirementsNotSatisfiedBy(
47404739
DC->getGenericSignatureOfContext());
@@ -4980,7 +4979,7 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
49804979
// an error, we can handle it as part of the above checkGenericArguments()
49814980
// call by passing in a superclass-bound archetype for the 'self' type
49824981
// instead of the concrete class type itself.
4983-
if (auto *classDecl = Adoptee->getClassOrBoundGenericClass()) {
4982+
if (auto *classDecl = DC->getSelfClassDecl()) {
49844983
if (!classDecl->isSemanticallyFinal()) {
49854984
if (auto req = hasInvariantSelfRequirement(proto, reqSig)) {
49864985
diagnoseInvariantSelfRequirement(Loc, Adoptee, proto, *req, diags);
@@ -5399,7 +5398,7 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
53995398
// Note that we check the module name to smooth over the difference
54005399
// between an imported Objective-C module and its overlay.
54015400
if (Proto->isSpecificProtocol(KnownProtocolKind::ObjectiveCBridgeable)) {
5402-
auto nominal = Adoptee->getAnyNominal();
5401+
auto nominal = DC->getSelfNominalTypeDecl();
54035402
if (!getASTContext().isTypeBridgedInExternalModule(nominal)) {
54045403
auto clangLoader = getASTContext().getClangModuleLoader();
54055404
if (nominal->getParentModule() != DC->getParentModule() &&

0 commit comments

Comments
 (0)