1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 20:12:21 +02:00

Fixed bug from new default ctor

This commit is contained in:
Brian Fiete 2020-01-25 10:04:52 -08:00
parent 6ba8bdc14c
commit c48c292f78
3 changed files with 44 additions and 29 deletions

View file

@ -93,6 +93,11 @@ namespace System.Threading
}
}
private this()
{
}
public this(ThreadStart start)
{
Debug.Assert(start != null);

View file

@ -5480,7 +5480,7 @@ BfTypedValue BfExprEvaluator::MatchConstructor(BfAstNode* targetSrc, BfMethodBou
if (callCtorBodyOnly)
{
// We're calling the base class's ctor from a derived class
if (checkProt == BfProtection_Private)
if (checkProt <= BfProtection_Private)
continue;
}
else

View file

@ -14408,52 +14408,62 @@ void BfModule::EmitCtorBody(bool& skipBody)
(baseType->mTypeDef != mCompiler->mBfObjectTypeDef))
{
// Try to find a ctor without any params first
bool foundBaseCtor = false;
BfMethodDef* matchedMethod = NULL;
bool hadCtorWithAllDefaults = false;
for (int pass = 0; pass < 2; pass++)
{
for (auto checkMethodDef : baseType->mTypeDef->mMethods)
baseType->mTypeDef->PopulateMemberSets();
BfMemberSetEntry* entry = NULL;
BfMethodDef* checkMethodDef = NULL;
baseType->mTypeDef->mMethodSet.TryGetWith(String("__BfCtor"), &entry);
if (entry != NULL)
checkMethodDef = (BfMethodDef*)entry->mMemberDef;
while (checkMethodDef != NULL)
{
bool allowPriv = checkMethodDef->mProtection != BfProtection_Private;
bool allowMethod = checkMethodDef->mProtection > BfProtection_Private;
// Allow calling of the default base ctor if it is implicitly defined
if ((checkMethodDef->mMethodDeclaration == NULL) && (pass == 1) && (!hadCtorWithAllDefaults))
allowPriv = true;
allowMethod = true;
if ((checkMethodDef->mMethodType == BfMethodType_Ctor) && (!checkMethodDef->mIsStatic) && (allowPriv))
if ((checkMethodDef->mMethodType == BfMethodType_Ctor) && (!checkMethodDef->mIsStatic) && (allowMethod))
{
if (checkMethodDef->mParams.size() == 0)
{
foundBaseCtor = true;
if (HasCompiledOutput())
{
SizedArray<BfIRValue, 1> args;
auto ctorBodyMethodInstance = GetMethodInstance(mCurTypeInstance->mBaseType, checkMethodDef, BfTypeVector());
if (!mCurTypeInstance->mBaseType->IsValuelessType())
{
auto basePtr = mBfIRBuilder->CreateBitCast(mCurMethodState->mLocals[0]->mValue, mBfIRBuilder->MapTypeInstPtr(mCurTypeInstance->mBaseType));
args.push_back(basePtr);
}
AddCallDependency(ctorBodyMethodInstance.mMethodInstance, true);
auto callInst = mBfIRBuilder->CreateCall(ctorBodyMethodInstance.mFunc, args);
auto callingConv = GetIRCallingConvention(ctorBodyMethodInstance.mMethodInstance);
if (callingConv != BfIRCallingConv_CDecl)
mBfIRBuilder->SetCallCallingConv(callInst, callingConv);
// if (!mCurTypeInstance->mBaseType->IsValuelessType())
// mBfIRBuilder->SetCallCallingConv(callInst, BfIRCallingConv_ThisCall);
break;
}
{
matchedMethod = checkMethodDef;
}
else if ((checkMethodDef->mParams[0]->mParamDeclaration != NULL) && (checkMethodDef->mParams[0]->mParamDeclaration->mInitializer != NULL))
hadCtorWithAllDefaults = true;
{
if (pass == 0)
hadCtorWithAllDefaults = true;
}
}
checkMethodDef = checkMethodDef->mNextWithSameName;
}
if (foundBaseCtor)
if (matchedMethod != NULL)
break;
}
if (!foundBaseCtor)
if ((HasCompiledOutput()) && (matchedMethod != NULL))
{
SizedArray<BfIRValue, 1> args;
auto ctorBodyMethodInstance = GetMethodInstance(mCurTypeInstance->mBaseType, matchedMethod, BfTypeVector());
if (!mCurTypeInstance->mBaseType->IsValuelessType())
{
auto basePtr = mBfIRBuilder->CreateBitCast(mCurMethodState->mLocals[0]->mValue, mBfIRBuilder->MapTypeInstPtr(mCurTypeInstance->mBaseType));
args.push_back(basePtr);
}
AddCallDependency(ctorBodyMethodInstance.mMethodInstance, true);
auto callInst = mBfIRBuilder->CreateCall(ctorBodyMethodInstance.mFunc, args);
auto callingConv = GetIRCallingConvention(ctorBodyMethodInstance.mMethodInstance);
if (callingConv != BfIRCallingConv_CDecl)
mBfIRBuilder->SetCallCallingConv(callInst, callingConv);
}
if (matchedMethod == NULL)
{
targetType = mCurTypeInstance->mBaseType;
if (ctorDeclaration != NULL)