1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Fixed lambda bind to delegate type with outer generic

This commit is contained in:
Brian Fiete 2020-10-08 06:45:04 -07:00
parent 58370d2c8c
commit 16cd9f7a77
4 changed files with 16 additions and 5 deletions

View file

@ -10456,9 +10456,8 @@ void BfExprEvaluator::Visit(BfDelegateBindExpression* delegateBindExpr)
Val128 hash128 = hashCtx.Finish128();
BfClosureType* checkClosureType = new BfClosureType(delegateTypeInstance, hash128);
checkClosureType->mContext = mModule->mContext;
checkClosureType->mBaseType = delegateTypeInstance;
BfType* resolvedClosureType = mModule->ResolveType(checkClosureType, BfPopulateType_Identity);
BfType* resolvedClosureType = mModule->ResolveType(checkClosureType, BfPopulateType_TypeDef);
closureTypeInst = (BfClosureType*)resolvedClosureType;
if (checkClosureType == resolvedClosureType)
{
@ -11413,7 +11412,7 @@ BfLambdaInstance* BfExprEvaluator::GetLambdaInstance(BfLambdaBindExpression* lam
BfClosureType* checkClosureType = new BfClosureType(delegateTypeInstance, hash128);
checkClosureType->mContext = mModule->mContext;
checkClosureType->mBaseType = delegateTypeInstance;
BfType* resolvedClosureType = mModule->ResolveType(checkClosureType, BfPopulateType_Identity);
BfType* resolvedClosureType = mModule->ResolveType(checkClosureType, BfPopulateType_TypeDef);
closureTypeInst = (BfClosureType*)resolvedClosureType;
if (checkClosureType == resolvedClosureType)
{

View file

@ -982,6 +982,9 @@ void BfModule::PopulateType(BfType* resolvedTypeRef, BfPopulateType populateType
if (!resolvedTypeRef->IsIncomplete())
return;
if (populateType <= BfPopulateType_TypeDef)
return;
auto typeInstance = resolvedTypeRef->ToTypeInstance();
CheckInjectNewRevision(typeInstance);

View file

@ -2289,7 +2289,8 @@ void BfClosureType::Init(BfProject* bfProject)
mTypeDef->mProject = bfProject;
mTypeDef->mTypeCode = srcTypeDef->mTypeCode;
mTypeDef->mName = system->GetAtom(srcTypeDef->mName->mString + mNameAdd);
mTypeDef->mOuterType = srcTypeDef->mOuterType;
// Purposely leave out 'mOuterType' - this fails if the outer type is generic
//mTypeDef->mOuterType = srcTypeDef->mOuterType;
mTypeDef->mNamespace = srcTypeDef->mNamespace;
system->AddNamespaceUsage(mTypeDef->mNamespace, mTypeDef->mProject);
mTypeDef->mHash = srcTypeDef->mHash;

View file

@ -98,6 +98,11 @@ namespace Tests
}
}
class ClassB<T>
{
public delegate int DelegateB(T val);
}
[Test]
public static void TestBasics()
{
@ -138,6 +143,9 @@ namespace Tests
val1.TestLambda();
ClassA ca = scope .();
ca.TestLambda();
ClassB<int8>.DelegateB dlg2 = scope (val) => val + 123;
Test.Assert(dlg2(3) == 126);
}
public static void Modify(ref int a, ref Splattable b)