Skip to content

Commit 939a861

Browse files
committed
[ConstraintSystem] Add a constraint locator path element for tuple types,
which will provide context for tuple element mismatch diagnostics.
1 parent bffba72 commit 939a861

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

include/swift/Sema/ConstraintLocator.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,20 @@ class LocatorPathElt::SynthesizedArgument final : public StoredIntegerElement<2>
581581
}
582582
};
583583

584+
class LocatorPathElt::TupleType : public StoredPointerElement<TypeBase> {
585+
public:
586+
TupleType(Type type)
587+
: StoredPointerElement(PathElementKind::TupleType, type.getPointer()) {
588+
assert(type->getDesugaredType()->is<swift::TupleType>());
589+
}
590+
591+
Type getType() const { return getStoredPointer(); }
592+
593+
static bool classof(const LocatorPathElt *elt) {
594+
return elt->getKind() == PathElementKind::TupleType;
595+
}
596+
};
597+
584598
/// Abstract superclass for any kind of tuple element.
585599
class LocatorPathElt::AnyTupleElement : public StoredIntegerElement<1> {
586600
protected:

include/swift/Sema/ConstraintLocatorPathElts.def

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ SIMPLE_LOCATOR_PATH_ELT(SubscriptMember)
164164
/// The missing argument synthesized by the solver.
165165
CUSTOM_LOCATOR_PATH_ELT(SynthesizedArgument)
166166

167+
/// A tuple type, which provides context for subsequent tuple element
168+
/// path components.
169+
CUSTOM_LOCATOR_PATH_ELT(TupleType)
170+
167171
/// Tuple elements.
168172
ABSTRACT_LOCATOR_PATH_ELT(AnyTupleElement)
169173
/// A tuple element referenced by position.

lib/Sema/ConstraintLocator.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ unsigned LocatorPathElt::getNewSummaryFlags() const {
6363
case ConstraintLocator::WrappedValue:
6464
case ConstraintLocator::GenericParameter:
6565
case ConstraintLocator::GenericArgument:
66+
case ConstraintLocator::TupleType:
6667
case ConstraintLocator::NamedTupleElement:
6768
case ConstraintLocator::TupleElement:
6869
case ConstraintLocator::ProtocolRequirement:
@@ -356,6 +357,12 @@ void ConstraintLocator::dump(SourceManager *sm, raw_ostream &out) const {
356357
out << "member reference base";
357358
break;
358359

360+
case TupleType: {
361+
auto tupleElt = elt.castTo<LocatorPathElt::TupleType>();
362+
out << "tuple type '" << tupleElt.getType()->getString(PO) << "'";
363+
break;
364+
}
365+
359366
case NamedTupleElement: {
360367
auto tupleElt = elt.castTo<LocatorPathElt::NamedTupleElement>();
361368
out << "named tuple element #" << llvm::utostr(tupleElt.getIndex());

lib/Sema/ConstraintSystem.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4273,6 +4273,10 @@ void constraints::simplifyLocator(ASTNode &anchor,
42734273
path = path.slice(1);
42744274
continue;
42754275

4276+
case ConstraintLocator::TupleType:
4277+
path = path.slice(1);
4278+
continue;
4279+
42764280
case ConstraintLocator::NamedTupleElement:
42774281
case ConstraintLocator::TupleElement: {
42784282
// Extract tuple element.

0 commit comments

Comments
 (0)