mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Defer fix for typed primitive/valueless target
This commit is contained in:
parent
7206038cc5
commit
b9647d2a08
2 changed files with 30 additions and 4 deletions
|
@ -399,10 +399,10 @@ bool BfModule::AddDeferredCallEntry(BfDeferredCallEntry* deferredCallEntry, BfSc
|
|||
|
||||
int dataIdx = 2;
|
||||
int argIdx = 0;
|
||||
if (!methodDef->mIsStatic)
|
||||
if ((!methodDef->mIsStatic) && (!owningType->IsValuelessType()))
|
||||
{
|
||||
gepInstance = mBfIRBuilder->CreateInBoundsGEP(deferredAlloca, 0, 2);
|
||||
if (owningType->IsStruct())
|
||||
if (owningType->IsValueType())
|
||||
{
|
||||
if ((!methodDef->mIsMutating) && (owningType->IsSplattable()))
|
||||
{
|
||||
|
@ -1172,7 +1172,7 @@ void BfModule::EmitDeferredCallProcessor(BfScopeData* scopeData, SLIList<BfDefer
|
|||
if ((argIdx == 0) && (!methodDef->mIsStatic))
|
||||
{
|
||||
// 'this'
|
||||
isStruct = methodOwner->IsStruct();
|
||||
isStruct = methodOwner->IsValueType();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1750,7 +1750,7 @@ BfLocalVariable* BfModule::HandleVariableDeclaration(BfVariableDeclaration* varD
|
|||
BfExprEvaluator valExprEvaluator(this);
|
||||
valExprEvaluator.mAllowReadOnlyReference = isReadOnly;
|
||||
initValue = CreateValueFromExpression(valExprEvaluator, varDecl->mInitializer, expectedType, (BfEvalExprFlags)(BfEvalExprFlags_NoCast | BfEvalExprFlags_AllowRefExpr | BfEvalExprFlags_VariableDeclaration));
|
||||
|
||||
|
||||
if ((initValue) && (resolvedType->IsUndefSizedArray()))
|
||||
{
|
||||
int stringId = GetStringPoolIdx(initValue.mValue, mBfIRBuilder);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Tests
|
||||
{
|
||||
|
@ -43,6 +44,23 @@ namespace Tests
|
|||
str.Contains('T');
|
||||
}*/
|
||||
|
||||
static int sVal = 123;
|
||||
|
||||
struct DisposableInstance : int32
|
||||
{
|
||||
public void Dispose() mut
|
||||
{
|
||||
sVal++;
|
||||
}
|
||||
}
|
||||
|
||||
DisposableInstance sDisposableInstance = (.)123;
|
||||
|
||||
static Result<DisposableInstance> GetDisposable(StringView profileDesc = default, int sampleRate = -1)
|
||||
{
|
||||
return DisposableInstance();
|
||||
}
|
||||
|
||||
public static void Defer0(ref int val)
|
||||
{
|
||||
for (int i < 10)
|
||||
|
@ -53,7 +71,14 @@ namespace Tests
|
|||
}
|
||||
|
||||
if (i == 2)
|
||||
{
|
||||
if (GetDisposable() case .Ok(var sampInst))
|
||||
{
|
||||
defer:: sampInst.Dispose();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
defer::
|
||||
{
|
||||
|
@ -68,6 +93,7 @@ namespace Tests
|
|||
int a = 0;
|
||||
Defer0(ref a);
|
||||
Test.Assert(a == 302);
|
||||
Test.Assert(sVal == 124);
|
||||
}
|
||||
|
||||
public static mixin GetStr()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue