Repository: dotnet/runtime
File: src/coreclr/vm/siginfo.cpp (C++)

Code before:
                        {
                            typeHnd = ClassLoader::CanonicalizeGenericArg(typeHnd);
                        }
                    }
                    thisinst[i] = typeHnd;
                    IfFailThrowBF(psig.SkipExactlyOne(), BFA_BAD_SIGNATURE, pOrigModule);
                }

                // If we failed to get all of the instantiation type arguments then we return the null type handle
                if (thisinst == NULL)
                {
                    thRet = TypeHandle();
                    break;
                }

                Instantiation genericLoadInst(thisinst, ntypars);

                if (ClassLoader::EligibleForSpecialMarkerTypeUsage(genericLoadInst, pMTInterfaceMapOwner))
                {
                    thRet = ClassLoader::LoadTypeDefThrowing(pGenericTypeModule, tkGenericType, ClassLoader::ThrowIfNotFound, ClassLoader::PermitUninstDefOrRef, 0, level);
                    if (thRet.AsMethodTable()->GetInstantiation()[0] == pMTInterfaceMapOwner->GetSpecialInstantiationType())
                    {
                        // We loaded the special marker type, but it is ALSO the exact expected type which isn't a valid combination
                        // In this case return something else (object) to indicate that
                        // we found an invalid situation and this function should be retried without the special marker type logic enabled.
                        thRet = TypeHandle(CoreLibBinder::GetElementType(ELEMENT_TYPE_OBJECT));
                        break;
                    }
                }
                else
                {
                    // Group together the current signature type context and substitution chain, which
                    // we may later use to instantiate constraints of type arguments that turn out to be
                    // typespecs, i.e. generic types.
                    InstantiationContext instContext(pTypeContext, pSubst);

                    // Now make the instantiated type
                    // The class loader will check the arity
                    // When we know it was correctly computed at NGen time, we ask the class loader to skip that check.
                    TypeHandle thFound = (ClassLoader::LoadGenericInstantiationThrowing(pGenericTypeModule,
                                                                        tkGenericType,
                                                                        genericLoadInst,
                                                                        fLoadTypes, level,
                                                                        &instContext,
                                                                        pZapSigContext && pZapSigContext->externalTokens == ZapSig::NormalTokens));

                    if (!thFound.IsNull() && pMTInterfaceMapOwner != NULL && !thFound.IsTypeDesc() && thFound.AsMethodTable()->IsSpecialMarkerTypeForGenericCasting())
                    {
                        // We are trying to load an interface instantiation, and we have a concept of the special marker type enabled, but
                        // the loaded type is not the expected type we should be looking for to return a special marker type, but the normal load has
                        // found a type which claims to be a special marker type. In this case return something else (object) to indicate that

Review comment (suggestion):
```suggestion
                        thRet = TypeHandle(g_pObjectClass);
```
Nit: We have a shortcut for this

Code after:
                        {
                            typeHnd = ClassLoader::CanonicalizeGenericArg(typeHnd);
                        }
                    }
                    thisinst[i] = typeHnd;
                    IfFailThrowBF(psig.SkipExactlyOne(), BFA_BAD_SIGNATURE, pOrigModule);
                }

                // If we failed to get all of the instantiation type arguments then we return the null type handle
                if (thisinst == NULL)
                {
                    thRet = TypeHandle();
                    break;
                }

                Instantiation genericLoadInst(thisinst, ntypars);

                if (ClassLoader::EligibleForSpecialMarkerTypeUsage(genericLoadInst, pMTInterfaceMapOwner))
                {
                    thRet = ClassLoader::LoadTypeDefThrowing(pGenericTypeModule, tkGenericType, ClassLoader::ThrowIfNotFound, ClassLoader::PermitUninstDefOrRef, 0, level);
                    if (thRet.AsMethodTable()->GetInstantiation()[0] == pMTInterfaceMapOwner->GetSpecialInstantiationType())
                    {
                        // We loaded the special marker type, but it is ALSO the exact expected type which isn't a valid combination
                        // In this case return something else (object) to indicate that
                        // we found an invalid situation and this function should be retried without the special marker type logic enabled.
                        thRet = TypeHandle(g_pObjectClass);
                        break;
                    }
                }
                else
                {
                    // Group together the current signature type context and substitution chain, which
                    // we may later use to instantiate constraints of type arguments that turn out to be
                    // typespecs, i.e. generic types.
                    InstantiationContext instContext(pTypeContext, pSubst);

                    // Now make the instantiated type
                    // The class loader will check the arity
                    // When we know it was correctly computed at NGen time, we ask the class loader to skip that check.
                    TypeHandle thFound = (ClassLoader::LoadGenericInstantiationThrowing(pGenericTypeModule,
                                                                        tkGenericType,
                                                                        genericLoadInst,
                                                                        fLoadTypes, level,
                                                                        &instContext,
                                                                        pZapSigContext && pZapSigContext->externalTokens == ZapSig::NormalTokens));

                    if (!thFound.IsNull() && pMTInterfaceMapOwner != NULL && !thFound.IsTypeDesc() && thFound.AsMethodTable()->IsSpecialMarkerTypeForGenericCasting())
                    {
                        // We are trying to load an interface instantiation, and we have a concept of the special marker type enabled, but
                        // the loaded type is not the expected type we should be looking for to return a special marker type, but the normal load has
                        // found a type which claims to be a special marker type. In this case return something else (object) to indicate that