@@ -1528,6 +1528,39 @@ class NominalOrBoundGenericNominalType : public AnyGenericType {
15281528};
15291529DEFINE_EMPTY_CAN_TYPE_WRAPPER (NominalOrBoundGenericNominalType, AnyGenericType)
15301530
1531+ // / InverseType represents the "inverse" of a ProtocolType as a constraint.
1532+ // / An inverse represents the _absence_ of an implicit constraint to the given
1533+ // / protocol. It is not a real type.
1534+ class InverseType final : public TypeBase {
1535+ Type protocol;
1536+
1537+ // The Error type is always canonical.
1538+ InverseType (Type type,
1539+ const ASTContext *canonicalContext,
1540+ RecursiveTypeProperties properties)
1541+ : TypeBase(TypeKind::Inverse, canonicalContext, properties),
1542+ protocol (type) {
1543+ assert (protocol->is <ProtocolType>());
1544+ }
1545+
1546+ public:
1547+ // / Produce an inverse constraint type for the given protocol type.
1548+ static Type get (Type protocolType);
1549+
1550+
1551+ Type getInvertedProtocol () const {
1552+ return protocol;
1553+ }
1554+
1555+ // Implement isa/cast/dyncast/etc.
1556+ static bool classof (const TypeBase *T) {
1557+ return T->getKind () == TypeKind::Inverse;
1558+ }
1559+ };
1560+ BEGIN_CAN_TYPE_WRAPPER (InverseType, Type)
1561+ PROXY_CAN_TYPE_SIMPLE_GETTER(getInvertedProtocol)
1562+ END_CAN_TYPE_WRAPPER(InverseType, Type)
1563+
15311564// / ErrorType - Represents the type of an erroneously constructed declaration,
15321565// / expression, or type. When creating ErrorTypes, an associated error
15331566// / diagnostic should always be emitted. That way when later stages of
@@ -7217,7 +7250,8 @@ inline bool TypeBase::isConstraintType() const {
72177250inline bool CanType::isConstraintTypeImpl (CanType type) {
72187251 return (isa<ProtocolType>(type) ||
72197252 isa<ProtocolCompositionType>(type) ||
7220- isa<ParameterizedProtocolType>(type));
7253+ isa<ParameterizedProtocolType>(type) ||
7254+ isa<InverseType>(type));
72217255}
72227256
72237257inline bool TypeBase::isExistentialType () {
0 commit comments