mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Fixed invalid generic inference from generic constraints
This commit is contained in:
parent
4189d10f41
commit
03e28f3add
4 changed files with 35 additions and 3 deletions
|
@ -85,5 +85,23 @@ namespace IDETest
|
|||
{
|
||||
|
||||
}
|
||||
|
||||
public static void TestGen<T, TItem>(T val)
|
||||
where T : IEnumerator<TItem>
|
||||
where TItem : var
|
||||
{
|
||||
Console.WriteLine(typeof(decltype(val)).ToString(.. scope .()));
|
||||
}
|
||||
|
||||
public static void TestPreGen<T>()
|
||||
{
|
||||
T a = default;
|
||||
TestGen(a); //FAIL Unable to determine generic argument 'TItem'
|
||||
}
|
||||
|
||||
public static void TestGenBug()
|
||||
{
|
||||
TestPreGen<List<int>>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -243,6 +243,16 @@ bool BfGenericInferContext::InferGenericArgument(BfMethodInstance* methodInstanc
|
|||
if (argType == NULL)
|
||||
return false;
|
||||
|
||||
if (mIgnoreMethodGenericParam)
|
||||
{
|
||||
if (argType->IsGenericParam())
|
||||
{
|
||||
auto genericParamType = (BfGenericParamType*)argType;
|
||||
if (genericParamType->mGenericParamKind == BfGenericParamKind_Method)
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!wantType->IsUnspecializedType())
|
||||
return true;
|
||||
|
||||
|
@ -623,10 +633,12 @@ bool BfGenericInferContext::InferGenericArguments(BfMethodInstance* methodInstan
|
|||
else
|
||||
genericParam = mModule->GetGenericParamInstance(genericParamType);
|
||||
|
||||
// Generic arg references in constraints refer to the caller, not the callee -- so ignore those
|
||||
SetAndRestoreValue<bool> prevIgnoreMethodGenericArg(mIgnoreMethodGenericParam, true);
|
||||
if (genericParam->mTypeConstraint != NULL)
|
||||
InferGenericArgument(methodInstance, genericParam->mTypeConstraint, ifaceConstraint, BfIRValue());
|
||||
for (auto argIfaceConstraint : genericParam->mInterfaceConstraints)
|
||||
InferGenericArgument(methodInstance, argIfaceConstraint, ifaceConstraint, BfIRValue());
|
||||
InferGenericArgument(methodInstance, argIfaceConstraint, ifaceConstraint, BfIRValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,12 +138,14 @@ public:
|
|||
BfTypeVector* mCheckMethodGenericArguments;
|
||||
SizedArray<BfIRValue, 4> mPrevArgValues;
|
||||
int mInferredCount;
|
||||
bool mIgnoreMethodGenericParam;
|
||||
|
||||
public:
|
||||
BfGenericInferContext()
|
||||
{
|
||||
mModule = NULL;
|
||||
mInferredCount = 0;
|
||||
mIgnoreMethodGenericParam = false;
|
||||
}
|
||||
bool InferGenericArgument(BfMethodInstance* methodInstance, BfType* argType, BfType* wantType, BfIRValue argValue);
|
||||
int GetUnresolvedCount()
|
||||
|
|
|
@ -7483,8 +7483,8 @@ String BfModule::GenericParamSourceToString(const BfGenericParamSource & generic
|
|||
{
|
||||
if (genericParamSource.mMethodInstance != NULL)
|
||||
{
|
||||
auto methodInst = GetUnspecializedMethodInstance(genericParamSource.mMethodInstance, false);
|
||||
SetAndRestoreValue<BfMethodInstance*> prevMethodInst(methodInst, NULL);
|
||||
//auto methodInst = GetUnspecializedMethodInstance(genericParamSource.mMethodInstance, false);
|
||||
//SetAndRestoreValue<BfMethodInstance*> prevMethodInst(mCurMethodInstance, methodInst);
|
||||
return MethodToString(genericParamSource.mMethodInstance);
|
||||
}
|
||||
else
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue