@@ -1125,18 +1125,41 @@ deriveBodyHashable_hashValue(AbstractFunctionDecl *hashValueDecl, void *) {
1125
1125
1126
1126
// return _hashValue(for: self)
1127
1127
auto *hashFunc = C.getHashValueForDecl ();
1128
- auto hashExpr = new (C) DeclRefExpr (hashFunc, DeclNameLoc (),
1128
+ if (!hashFunc->hasInterfaceType ())
1129
+ C.getLazyResolver ()->resolveDeclSignature (hashFunc);
1130
+
1131
+ auto selfType = hashValueDecl->mapTypeIntoContext (
1132
+ parentDC->getSelfInterfaceType ());
1133
+ auto hashableProto = C.getProtocol (KnownProtocolKind::Hashable);
1134
+ auto conformance = TypeChecker::conformsToProtocol (selfType, hashableProto,
1135
+ parentDC, None);
1136
+ auto subs = SubstitutionMap::get (hashFunc->getGenericSignature (),
1137
+ ArrayRef<Type>(selfType),
1138
+ ArrayRef<ProtocolConformanceRef>(*conformance));
1139
+ ConcreteDeclRef hashRef (hashFunc, subs);
1140
+
1141
+ auto hashExpr = new (C) DeclRefExpr (hashRef, DeclNameLoc (),
1129
1142
/* implicit*/ true );
1143
+
1144
+ Type intType = C.getIntDecl ()->getDeclaredType ();
1145
+ hashExpr->setType (FunctionType::get (AnyFunctionType::Param (selfType),
1146
+ intType));
1147
+
1130
1148
auto selfDecl = hashValueDecl->getImplicitSelfDecl ();
1131
1149
auto selfRef = new (C) DeclRefExpr (selfDecl, DeclNameLoc (),
1132
1150
/* implicit*/ true );
1133
- auto callExpr = CallExpr::createImplicit (C, hashExpr,
1134
- { selfRef }, { C.Id_for });
1151
+ selfRef->setType (selfType);
1152
+
1153
+ auto callExpr = CallExpr::createImplicit (C, hashExpr, { selfRef }, { });
1154
+ callExpr->setType (intType);
1155
+ callExpr->setThrows (false );
1156
+
1135
1157
auto returnStmt = new (C) ReturnStmt (SourceLoc (), callExpr);
1136
1158
1137
1159
auto body = BraceStmt::create (C, SourceLoc (), {returnStmt}, SourceLoc (),
1138
1160
/* implicit*/ true );
1139
1161
hashValueDecl->setBody (body);
1162
+ hashValueDecl->setBodyTypeCheckedIfPresent ();
1140
1163
}
1141
1164
1142
1165
// / Derive a 'hashValue' implementation.
0 commit comments