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

Fixed missing error for outer static instance-qualified lookup

This commit is contained in:
Brian Fiete 2025-01-05 09:34:21 -08:00
parent 61a3328c5a
commit 40a9dbf25c
3 changed files with 30 additions and 15 deletions

View file

@ -5206,7 +5206,13 @@ BfTypedValue BfExprEvaluator::LoadField(BfAstNode* targetSrc, BfTypedValue targe
if (fieldDef->mIsStatic)
{
if ((target) && ((flags & BfLookupFieldFlag_IsImplicitThis) == 0) && (!typeInstance->mTypeDef->IsGlobalsContainer()))
if (target)
{
//BF_ASSERT((flags & BfLookupFieldFlag_HasInstance) != 0);
flags = (BfLookupFieldFlags)(flags | BfLookupFieldFlag_HasInstance);
}
if (((flags & BfLookupFieldFlag_HasInstance) != 0) && ((flags & BfLookupFieldFlag_IsImplicitThis) == 0) && (!typeInstance->mTypeDef->IsGlobalsContainer()))
{
//CS0176: Member 'Program.sVal' cannot be accessed with an instance reference; qualify it with a type name instead
mModule->Fail(StrFormat("Member '%s.%s' cannot be accessed with an instance reference; qualify it with a type name instead",
@ -5507,6 +5513,9 @@ BfTypedValue BfExprEvaluator::LoadField(BfAstNode* targetSrc, BfTypedValue targe
BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue target, const StringImpl& fieldName, BfLookupFieldFlags flags)
{
if (target)
flags = (BfLookupFieldFlags)(flags | BfLookupFieldFlag_HasInstance);
if ((target.mType != NULL && (target.mType->IsGenericParam())))
{
auto genericParamType = (BfGenericParamType*)target.mType;
@ -5726,7 +5735,7 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
auto checkProtection = field->mProtection;
if (checkProtection == BfProtection_Hidden)
{
// Allow acessing hidden fields
// Allow accessing hidden fields
checkProtection = BfProtection_Private;
}
@ -6016,13 +6025,18 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
curCheckType = curCheckType->mBaseType;
}
}
auto outerTypeDef = mModule->GetOuterType(startCheckType);
if (outerTypeDef != NULL)
{
BfLookupFieldFlags newFlags = BfLookupFieldFlag_CheckingOuter;
if (((flags & BfLookupFieldFlag_HasInstance) != 0) &&
((flags & BfLookupFieldFlag_IsImplicitThis) == 0))
newFlags = (BfLookupFieldFlags)(newFlags | BfLookupFieldFlag_HasInstance);
// Check statics in outer type
return LookupField(targetSrc, BfTypedValue(outerTypeDef), fieldName, BfLookupFieldFlag_CheckingOuter);
}
return LookupField(targetSrc, BfTypedValue(outerTypeDef), fieldName, newFlags);
}
return BfTypedValue();
}

View file

@ -379,7 +379,8 @@ enum BfLookupFieldFlags
BfLookupFieldFlag_IgnoreProtection = 8,
BfLookupFieldFlag_BindOnly = 0x10,
BfLookupFieldFlag_IsFailurePass = 0x20,
BfLookupFieldFlag_IsAnonymous = 0x40
BfLookupFieldFlag_IsAnonymous = 0x40,
BfLookupFieldFlag_HasInstance = 0x80
};
enum BfUnaryOpFlags

View file

@ -129,8 +129,8 @@ namespace Tests
{
public int Test;
}
public static List<CTest> mList = new .() ~ delete _;
private static Event<EventHandler> mEvent;
public static List<CTest> sList = new .() ~ delete _;
private static Event<EventHandler> sEvent;
[Test]
public static void TestBasics()
@ -161,17 +161,17 @@ namespace Tests
TestA ta = scope .();
ta.Vec = .(33, 44);
mList.Add(scope .());
mEvent.Add(new (sender, e) =>
sList.Add(scope .());
sEvent.Add(new (sender, e) =>
{
mList.ForEach((b) => { b.Test = 1; });
sList.ForEach((b) => { b.Test = 1; });
});
mEvent(null, .Empty);
mEvent.Dispose();
Test.Assert(mList.Back.Test == 1);
sEvent(null, .Empty);
sEvent.Dispose();
Test.Assert(sList.Back.Test == 1);
int i = 0;
mList.ForEach((l) => l.mList.ForEach((l) =>
sList.ForEach((l) => sList.ForEach((l) =>
{
i++;
}));