| 300 | } |
| 301 | |
| 302 | bool BfGenericInferContext::InferGenericArgument(BfMethodInstance* methodInstance, BfType* argType, BfType* wantType, BfIRValue argValue, bool checkCheckedSet) |
| 303 | { |
| 304 | if (argType == NULL) |
| 305 | return false; |
| 306 | |
| 307 | if (!wantType->IsUnspecializedType()) |
| 308 | return true; |
| 309 | |
| 310 | if (checkCheckedSet) |
| 311 | { |
| 312 | if (!AddToCheckedSet(argType, wantType)) |
| 313 | return true; |
| 314 | } |
| 315 | |
| 316 | if (wantType->IsGenericParam()) |
| 317 | { |
| 318 | auto wantGenericParam = (BfGenericParamType*)wantType; |
| 319 | |
| 320 | BfType* methodGenericTypeConstraint = NULL; |
| 321 | auto _SetGeneric = [&]() |
| 322 | { |
| 323 | if (argType != NULL) |
| 324 | { |
| 325 | // Disallow illegal types |
| 326 | if (argType->IsRef()) |
| 327 | return; |
| 328 | if (argType->IsNull()) |
| 329 | return; |
| 330 | } |
| 331 | |
| 332 | if ((*mCheckMethodGenericArguments)[wantGenericParam->mGenericParamIdx] != argType) |
| 333 | { |
| 334 | if (methodGenericTypeConstraint != NULL) |
| 335 | { |
| 336 | if (methodGenericTypeConstraint->IsGenericTypeInstance()) |
| 337 | { |
| 338 | auto wantGenericType = (BfTypeInstance*)methodGenericTypeConstraint; |
| 339 | |
| 340 | auto checkArgType = argType; |
| 341 | while (checkArgType != NULL) |
| 342 | { |
| 343 | if (checkArgType->IsGenericTypeInstance()) |
| 344 | { |
| 345 | auto argGenericType = (BfTypeInstance*)checkArgType; |
| 346 | if (argGenericType->mTypeDef->GetLatest() == wantGenericType->mTypeDef->GetLatest()) |
| 347 | { |
| 348 | for (int genericArgIdx = 0; genericArgIdx < (int)argGenericType->mGenericTypeInfo->mTypeGenericArguments.size(); genericArgIdx++) |
| 349 | InferGenericArgument(methodInstance, argGenericType->mGenericTypeInfo->mTypeGenericArguments[genericArgIdx], wantGenericType->mGenericTypeInfo->mTypeGenericArguments[genericArgIdx], BfIRValue(), true); |
| 350 | } |
| 351 | } |
| 352 | else if (checkArgType->IsSizedArray()) |
| 353 | { |
| 354 | auto sizedArrayType = (BfSizedArrayType*)checkArgType; |
| 355 | if (wantGenericType->IsInstanceOf(mModule->mCompiler->mSizedArrayTypeDef)) |
| 356 | { |
| 357 | InferGenericArgument(methodInstance, sizedArrayType->mElementType, wantGenericType->mGenericTypeInfo->mTypeGenericArguments[0], BfIRValue()); |
| 358 | auto intType = mModule->GetPrimitiveType(BfTypeCode_IntPtr); |
| 359 | BfTypedValue arraySize = BfTypedValue(mModule->mBfIRBuilder->CreateConst(BfTypeCode_IntPtr, (uint64)sizedArrayType->mElementCount), intType); |
no test coverage detected