mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Fixed readonly ref pointing to global variable
This commit is contained in:
parent
70bb55d779
commit
989e8455e8
1 changed files with 24 additions and 0 deletions
|
@ -4341,6 +4341,30 @@ BfTypedValue BfExprEvaluator::LoadLocal(BfLocalVariable* varDecl, bool allowRef)
|
|||
else if (varDecl->mConstValue)
|
||||
{
|
||||
localResult = BfTypedValue(varDecl->mConstValue, varDecl->mResolvedType, false);
|
||||
|
||||
if ((varDecl->mResolvedType->IsRef()) && (!allowRef))
|
||||
{
|
||||
BfRefType* refType = (BfRefType*)varDecl->mResolvedType;
|
||||
BfType* innerType = refType->mElementType;
|
||||
|
||||
if (innerType->IsValuelessNonOpaqueType())
|
||||
{
|
||||
if (refType->mRefKind == BfRefType::RefKind_Mut)
|
||||
return BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), innerType, BfTypedValueKind_MutableValue);
|
||||
return BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), innerType, varDecl->mIsReadOnly ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr);
|
||||
}
|
||||
|
||||
if (refType->mRefKind == BfRefType::RefKind_Mut)
|
||||
{
|
||||
if (innerType->IsGenericParam())
|
||||
{
|
||||
localResult = BfTypedValue(varDecl->mConstValue, innerType, BfTypedValueKind_MutableValue);
|
||||
return localResult;
|
||||
}
|
||||
}
|
||||
|
||||
localResult = BfTypedValue(varDecl->mConstValue, innerType, varDecl->mIsReadOnly ? BfTypedValueKind_ReadOnlyAddr : BfTypedValueKind_Addr);
|
||||
}
|
||||
}
|
||||
else if (varDecl->mIsSplat)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue