@@ -1132,19 +1132,47 @@ deriveBodyHashable_hashValue(AbstractFunctionDecl *hashValueDecl, void *) {
1132
1132
ASTContext &C = parentDC->getASTContext ();
1133
1133
1134
1134
// return _hashValue(for: self)
1135
- auto *hashFunc = C.getHashValueForDecl ();
1136
- auto hashExpr = new (C) DeclRefExpr (hashFunc, DeclNameLoc (),
1137
- /* implicit*/ true );
1135
+
1136
+ // 'self'
1138
1137
auto selfDecl = hashValueDecl->getImplicitSelfDecl ();
1138
+ Type selfType = selfDecl->getType ();
1139
1139
auto selfRef = new (C) DeclRefExpr (selfDecl, DeclNameLoc (),
1140
- /* implicit*/ true );
1140
+ /* implicit*/ true ,
1141
+ AccessSemantics::Ordinary,
1142
+ selfType);
1143
+
1144
+ // _hashValue(for:)
1145
+ auto *hashFunc = C.getHashValueForDecl ();
1146
+ auto substitutions = SubstitutionMap::get (
1147
+ hashFunc->getGenericSignature (),
1148
+ [&](SubstitutableType *dependentType) {
1149
+ if (auto gp = dyn_cast<GenericTypeParamType>(dependentType)) {
1150
+ if (gp->getDepth () == 0 && gp->getIndex () == 0 )
1151
+ return selfType;
1152
+ }
1153
+
1154
+ return Type (dependentType);
1155
+ },
1156
+ LookUpConformanceInModule (hashValueDecl->getModuleContext ()));
1157
+ ConcreteDeclRef hashFuncRef (hashFunc, substitutions);
1158
+
1159
+
1160
+ Type hashFuncType = hashFunc->getInterfaceType ().subst (substitutions);
1161
+ auto hashExpr = new (C) DeclRefExpr (hashFuncRef, DeclNameLoc (),
1162
+ /* implicit*/ true ,
1163
+ AccessSemantics::Ordinary,
1164
+ hashFuncType);
1165
+ Type hashFuncResultType =
1166
+ hashFuncType->castTo <AnyFunctionType>()->getResult ();
1141
1167
auto callExpr = CallExpr::createImplicit (C, hashExpr,
1142
1168
{ selfRef }, { C.Id_for });
1169
+ callExpr->setType (hashFuncResultType);
1170
+
1143
1171
auto returnStmt = new (C) ReturnStmt (SourceLoc (), callExpr);
1144
1172
1145
1173
auto body = BraceStmt::create (C, SourceLoc (), {returnStmt}, SourceLoc (),
1146
1174
/* implicit*/ true );
1147
- return { body, /* isTypeChecked=*/ false };
1175
+ return { body, /* isTypeChecked=*/ true };
1148
1176
}
1149
1177
1150
1178
// / Derive a 'hashValue' implementation.
0 commit comments