Skip to content

Commit 67d3ede

Browse files
committed
Sema: Teach the solver to find members of tuples
1 parent de0fd63 commit 67d3ede

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8229,27 +8229,24 @@ performMemberLookup(ConstraintKind constraintKind, DeclNameRef memberName,
82298229
// of the tuple.
82308230
auto &ctx = getASTContext();
82318231
if (auto baseTuple = baseObjTy->getAs<TupleType>()) {
8232-
// Tuples don't have compound-name members.
8233-
if (!memberName.isSimpleName() || memberName.isSpecial())
8234-
return result; // No result.
8235-
8236-
StringRef nameStr = memberName.getBaseIdentifier().str();
8237-
int fieldIdx = -1;
8238-
// Resolve a number reference into the tuple type.
8239-
unsigned Value = 0;
8240-
if (!nameStr.getAsInteger(10, Value) &&
8241-
Value < baseTuple->getNumElements()) {
8242-
fieldIdx = Value;
8243-
} else {
8244-
fieldIdx = baseTuple->getNamedElementId(memberName.getBaseIdentifier());
8232+
if (!memberName.isSpecial()) {
8233+
StringRef nameStr = memberName.getBaseIdentifier().str();
8234+
int fieldIdx = -1;
8235+
// Resolve a number reference into the tuple type.
8236+
unsigned Value = 0;
8237+
if (!nameStr.getAsInteger(10, Value) &&
8238+
Value < baseTuple->getNumElements()) {
8239+
fieldIdx = Value;
8240+
} else {
8241+
fieldIdx = baseTuple->getNamedElementId(memberName.getBaseIdentifier());
8242+
}
8243+
8244+
if (fieldIdx != -1) {
8245+
// Add an overload set that selects this field.
8246+
result.ViableCandidates.push_back(OverloadChoice(baseTy, fieldIdx));
8247+
return result;
8248+
}
82458249
}
8246-
8247-
if (fieldIdx == -1)
8248-
return result; // No result.
8249-
8250-
// Add an overload set that selects this field.
8251-
result.ViableCandidates.push_back(OverloadChoice(baseTy, fieldIdx));
8252-
return result;
82538250
}
82548251

82558252
if (auto *selfTy = instanceTy->getAs<DynamicSelfType>())

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3621,6 +3621,12 @@ Type ConstraintSystem::simplifyTypeImpl(Type type,
36213621
auto conformance = DC->getParentModule()->lookupConformance(
36223622
lookupBaseType, proto);
36233623
if (!conformance) {
3624+
// FIXME: This regresses diagnostics if removed, but really the
3625+
// handling of a missing conformance should be the same for
3626+
// tuples and non-tuples.
3627+
if (lookupBaseType->is<TupleType>())
3628+
return DependentMemberType::get(lookupBaseType, assocType);
3629+
36243630
// If the base type doesn't conform to the associatedtype's protocol,
36253631
// there will be a missing conformance fix applied in diagnostic mode,
36263632
// so the concrete dependent member type is considered a "hole" in

0 commit comments

Comments
 (0)