Skip to content

Commit 2032969

Browse files
authored
Merge pull request #19220 from apple/revert-19202-rework-type-checking-designated-protocol
Revert "Store ProtocolDecl rather than TypeLoc for designated protocol."
2 parents 7ef1696 + 14b4f37 commit 2032969

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

include/swift/AST/Decl.h

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6272,7 +6272,7 @@ class OperatorDecl : public Decl {
62726272

62736273
Identifier DesignatedProtocolName;
62746274
SourceLoc DesignatedProtocolNameLoc;
6275-
ProtocolDecl *DesignatedProtocol;
6275+
TypeLoc DesignatedProtocolTypeLoc;
62766276

62776277
public:
62786278
OperatorDecl(DeclKind kind, DeclContext *DC, SourceLoc OperatorLoc,
@@ -6293,14 +6293,24 @@ class OperatorDecl : public Decl {
62936293
return DesignatedProtocolName;
62946294
}
62956295

6296+
void setDesignatedProtocolName(Identifier name) {
6297+
DesignatedProtocolName = name;
6298+
}
6299+
62966300
SourceLoc getDesignatedProtocolNameLoc() const {
62976301
return DesignatedProtocolNameLoc;
62986302
}
62996303

6300-
ProtocolDecl *getDesignatedProtocol() const { return DesignatedProtocol; }
6304+
void setDesignatedProtocolNameLoc(SourceLoc loc) {
6305+
DesignatedProtocolNameLoc = loc;
6306+
}
6307+
6308+
TypeLoc getDesignatedProtocolTypeLoc() const {
6309+
return DesignatedProtocolTypeLoc;
6310+
}
63016311

6302-
void setDesignatedProtocol(ProtocolDecl *protocol) {
6303-
DesignatedProtocol = protocol;
6312+
void setDesignatedProtocolTypeLoc(TypeLoc typeLoc) {
6313+
DesignatedProtocolTypeLoc = typeLoc;
63046314
}
63056315

63066316
static bool classof(const Decl *D) {

lib/Sema/TypeCheckDecl.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2074,14 +2074,14 @@ static void checkDesignatedProtocol(OperatorDecl *OD, Identifier name,
20742074
}
20752075

20762076
if (!typeLoc.isError()) {
2077+
OD->setDesignatedProtocolTypeLoc(typeLoc);
20772078
auto *decl = typeLoc.getType()->getNominalOrBoundGenericNominal();
20782079
if (!decl || !isa<ProtocolDecl>(decl)) {
20792080
tc.diagnose(typeLoc.getLoc(),
20802081
diag::operators_designated_protocol_not_a_protocol,
20812082
typeLoc.getType());
20822083
OD->setInvalid();
20832084
} else {
2084-
OD->setDesignatedProtocol(cast<ProtocolDecl>(decl));
20852085
// FIXME: verify this operator has a declaration within this
20862086
// protocol with the same arity and fixity
20872087
}
@@ -2104,9 +2104,9 @@ void TypeChecker::validateDecl(OperatorDecl *OD) {
21042104

21052105
// Pre- or post-fix operator?
21062106
if (!IOD) {
2107-
auto *protocol = OD->getDesignatedProtocol();
2107+
auto typeLoc = OD->getDesignatedProtocolTypeLoc();
21082108
auto protocolId = OD->getDesignatedProtocolName();
2109-
if (!protocol && !protocolId.empty() &&
2109+
if (typeLoc.isNull() && !protocolId.empty() &&
21102110
enableOperatorDesignatedProtocols) {
21112111
auto protocolIdLoc = OD->getDesignatedProtocolNameLoc();
21122112
checkDesignatedProtocol(OD, protocolId, protocolIdLoc, *this, Context);
@@ -2127,8 +2127,8 @@ void TypeChecker::validateDecl(OperatorDecl *OD) {
21272127
}
21282128

21292129
auto secondId = IOD->getSecondIdentifier();
2130-
auto *protocol = IOD->getDesignatedProtocol();
2131-
if (!protocol && enableOperatorDesignatedProtocols) {
2130+
auto typeLoc = IOD->getDesignatedProtocolTypeLoc();
2131+
if (typeLoc.isNull() && enableOperatorDesignatedProtocols) {
21322132
auto secondIdLoc = IOD->getSecondIdentifierLoc();
21332133
assert(secondId.empty() || !firstId.empty());
21342134

@@ -2140,7 +2140,7 @@ void TypeChecker::validateDecl(OperatorDecl *OD) {
21402140

21412141
if (!group && !IOD->isInvalid()) {
21422142
if (!firstId.empty() &&
2143-
(!secondId.empty() || !IOD->getDesignatedProtocol())) {
2143+
(!secondId.empty() || IOD->getDesignatedProtocolTypeLoc().isNull())) {
21442144
diagnose(firstIdLoc, diag::unknown_precedence_group, firstId);
21452145
IOD->setInvalid();
21462146
}

0 commit comments

Comments
 (0)