mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 20:42:21 +02:00
Improved struct returns from mixins and block expressions
This commit is contained in:
parent
5268e103e9
commit
e3ca70c153
3 changed files with 36 additions and 0 deletions
|
@ -798,6 +798,21 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void MakeTemporary(bool restricted = false)
|
||||
{
|
||||
switch (mKind)
|
||||
{
|
||||
case BfTypedValueKind_Addr:
|
||||
mKind = restricted ? BfTypedValueKind_RestrictedTempAddr : BfTypedValueKind_TempAddr;
|
||||
break;
|
||||
case BfTypedValueKind_ReadOnlyAddr:
|
||||
mKind = BfTypedValueKind_ReadOnlyTempAddr;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
bool CanModify() const;
|
||||
};
|
||||
|
||||
|
|
|
@ -3403,6 +3403,11 @@ void BfExprEvaluator::Visit(BfBlock* blockExpr)
|
|||
|
||||
mModule->VisitEmbeddedStatement(blockExpr, this, BfNodeIsA<BfUnscopedBlock>(blockExpr) ? BfEmbeddedStatementFlags_Unscoped : BfEmbeddedStatementFlags_None);
|
||||
mResult = mModule->SanitizeAddr(mResult);
|
||||
if ((mResult) && (mResult.mType->IsStruct()))
|
||||
{
|
||||
mResult = mModule->MakeAddressable(mResult, true);
|
||||
mResult.MakeTemporary(true);
|
||||
}
|
||||
}
|
||||
|
||||
bool BfExprEvaluator::CheckVariableDeclaration(BfAstNode* checkNode, bool requireSimpleIfExpr, bool exprMustBeTrue, bool silentFail)
|
||||
|
@ -17248,6 +17253,12 @@ void BfExprEvaluator::InjectMixin(BfAstNode* targetSrc, BfTypedValue target, boo
|
|||
|
||||
mModule->mBfIRBuilder->RestoreDebugLocation();
|
||||
mModule->mBfIRBuilder->DupDebugLocation();
|
||||
|
||||
if ((mResult) && (mResult.mType->IsStruct()))
|
||||
{
|
||||
mResult = mModule->MakeAddressable(mResult, true);
|
||||
mResult.MakeTemporary(true);
|
||||
}
|
||||
}
|
||||
|
||||
void BfExprEvaluator::SetMethodElementType(BfAstNode* target)
|
||||
|
|
|
@ -79,6 +79,11 @@ namespace Tests
|
|||
ref a
|
||||
}
|
||||
|
||||
static mixin Unwrap(var res)
|
||||
{
|
||||
res.Value
|
||||
}
|
||||
|
||||
[Test]
|
||||
public static void TestBasics()
|
||||
{
|
||||
|
@ -139,6 +144,11 @@ namespace Tests
|
|||
var c = { ref b };
|
||||
c = 99;
|
||||
Test.Assert(b == 99);
|
||||
|
||||
Result<StringView> svRes = "ab ";
|
||||
var sv2 = Unwrap!(svRes)..Trim();
|
||||
Test.Assert(svRes.Value == "ab ");
|
||||
Test.Assert(sv2 == "ab");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue