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

Fixed constrained property lookups

This commit is contained in:
Brian Fiete 2021-01-19 10:40:38 -08:00
parent 15c62583a2
commit 6d06ee3430
4 changed files with 139 additions and 19 deletions

View file

@ -8576,7 +8576,7 @@ BfTypedValue BfExprEvaluator::MatchMethod(BfAstNode* targetSrc, BfMethodBoundExp
prevBindResult.mPrevVal->mCheckedMultipleMethods = true;
BfModuleMethodInstance moduleMethodInstance = GetSelectedMethod(targetSrc, curTypeInst, methodDef, methodMatcher);
if (!mModule->CheckUseMethodInstance(moduleMethodInstance.mMethodInstance, targetSrc))
if ((moduleMethodInstance.mMethodInstance != NULL) && (!mModule->CheckUseMethodInstance(moduleMethodInstance.mMethodInstance, targetSrc)))
return BfTypedValue();
if ((mModule->mCurMethodInstance != NULL) && (mModule->mCurMethodInstance->mIsUnspecialized))
@ -16498,7 +16498,8 @@ BfModuleMethodInstance BfExprEvaluator::GetPropertyMethodInstance(BfMethodDef* m
if (bestMethodInstance != NULL)
{
mPropTarget = mOrigPropTarget;
mPropTarget.mType = checkTypeInst;
//mPropTarget.mType = checkTypeInst;
//mPropTarget = mModule->Cast( mOrigPropTarget, checkTypeInst);
return mModule->GetMethodInstanceAtIdx(ifaceMethodEntry.mMethodRef.mTypeInstance, ifaceMethodEntry.mMethodRef.mMethodNum);
}
}
@ -16638,9 +16639,23 @@ BfTypedValue BfExprEvaluator::GetResult(bool clearResult, bool resolveGenericTyp
if (!matchedMethod->mIsStatic)
{
auto owner = methodInstance.mMethodInstance->GetOwner();
if ((mPropTarget.mValue.IsFake()) && (!mOrigPropTarget.mValue.IsFake()))
bool isTypeMatch = mPropTarget.mType == owner;
if (owner->IsTypedPrimitive())
isTypeMatch |= mPropTarget.mType == owner->GetUnderlyingType();
if ((!isTypeMatch) ||
((mPropTarget.mValue.IsFake()) && (!mOrigPropTarget.mValue.IsFake())))
{
auto prevPropTarget = mPropTarget;
mPropTarget = mModule->Cast(mPropSrc, mOrigPropTarget, owner);
if (!mPropTarget)
{
mModule->Fail("Internal property error", mPropSrc);
return BfTypedValue();
}
}
if ((mPropGetMethodFlags & BfGetMethodInstanceFlag_DisableObjectAccessChecks) == 0)
@ -17439,6 +17454,11 @@ void BfExprEvaluator::DoTupleAssignment(BfAssignmentExpression* assignExpr)
void BfExprEvaluator::PerformAssignment(BfAssignmentExpression* assignExpr, bool evaluatedLeft, BfTypedValue rightValue, BfTypedValue* outCascadeValue)
{
if (assignExpr->ToString() == "state.StateMachine = this")
{
NOP;
}
auto binaryOp = BfAssignOpToBinaryOp(assignExpr->mOp);
BfExpression* targetNode = assignExpr->mLeft;
@ -17589,10 +17609,18 @@ void BfExprEvaluator::PerformAssignment(BfAssignmentExpression* assignExpr, bool
if (!setMethod->mIsStatic)
{
auto owner = methodInstance.mMethodInstance->GetOwner();
if (mPropTarget.mType != owner)
if ((mPropTarget.mType != owner) ||
((mPropTarget.mValue.IsFake()) && (!mOrigPropTarget.mValue.IsFake())))
{
if (mPropDefBypassVirtual)
if ((mPropDefBypassVirtual) || (!mPropTarget.mType->IsInterface()))
{
mPropTarget = mModule->Cast(mPropSrc, mOrigPropTarget, owner);
if (!mPropTarget)
{
mModule->Fail("Internal property error", mPropSrc);
return;
}
}
}
mModule->EmitObjectAccessCheck(mPropTarget);

View file

@ -14652,6 +14652,9 @@ void BfModule::CreateReturn(BfIRValue val)
return;
}
if (mCurMethodInstance->mReturnType->IsVar())
return;
if (mCurMethodInstance->mReturnType->IsValuelessType())
{
mBfIRBuilder->CreateRetVoid();
@ -14740,7 +14743,11 @@ void BfModule::EmitDefaultReturn()
}
else
{
if (mCurMethodInstance->mReturnType->IsVoid())
if (mCurMethodInstance->mReturnType->IsVar())
{
// Ignore
}
else if (mCurMethodInstance->mReturnType->IsVoid())
mBfIRBuilder->CreateRetVoid();
else if ((!mIsComptimeModule) && (mCurMethodInstance->GetStructRetIdx() == -1))
mBfIRBuilder->CreateRet(GetDefaultValue(mCurMethodInstance->mReturnType));
@ -18126,7 +18133,7 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
}
}
BfLogSysM("ProcessMethod %p Unspecialized: %d Module: %p IRFunction: %d Reified: %d\n", methodInstance, mCurTypeInstance->IsUnspecializedType(), this, methodInstance->mIRFunction.mId, methodInstance->mIsReified);
BfLogSysM("ProcessMethod %p Unspecialized: %d Module: %p IRFunction: %d Reified: %d Incomplete:%d\n", methodInstance, mCurTypeInstance->IsUnspecializedType(), this, methodInstance->mIRFunction.mId, methodInstance->mIsReified, mIncompleteMethodCount);
if (methodInstance->GetImportCallKind() != BfImportCallKind_None)
{
@ -18243,9 +18250,10 @@ void BfModule::ProcessMethod(BfMethodInstance* methodInstance, bool isInlineDup)
if (!unspecializedMethodInstance->mHasBeenProcessed)
{
// Make sure the unspecialized method is processed so we can take its bindings
// Clear mCurMethodState so we don't think we're in a local method
SetAndRestoreValue<BfMethodState*> prevMethodState_Unspec(mCurMethodState, prevMethodState.mPrevVal);
if (unspecializedMethodInstance->mMethodProcessRequest == NULL)
unspecializedMethodInstance->mDeclModule->mIncompleteMethodCount++;
mContext->ProcessMethod(unspecializedMethodInstance);
}
methodState.mGenericTypeBindings = &unspecializedMethodInstance->GetMethodInfoEx()->mGenericTypeBindings;

View file

@ -183,6 +183,13 @@ namespace Tests
IFaceA ifa = cba;
Test.Assert(ifa.GetType() == typeof(ClassB));
ClassF cf = scope .();
TestIFaceD(cf);
Test.Assert(cf.mA == 999);
ClassG cg = scope .();
TestIFaceD(cg);
Test.Assert(cg.mA == 999);
GameItem gameItem = scope .();
var hitbox = GetHitbox(gameItem);
Test.Assert(hitbox.mArea == .() { x=1, y=2, width=3, height=4 });
@ -267,6 +274,47 @@ namespace Tests
return T.SMethod2(val.GetVal());
}
interface IFaceD
{
int32 Val
{
get; set;
}
}
class ClassF : IFaceD
{
public int32 mA;
int32 IFaceD.Val
{
get
{
return mA;
}
set
{
mA = value;
}
}
}
class ClassG : ClassF
{
}
static void TestIFaceD<T>(T val) where T : IFaceD
{
val.Val = 999;
}
static int TestIFaceD2<T>(T val) where T : IFaceD
{
return val.Val;
}
[Test]
public static void TestDefaults()
{
@ -297,6 +345,15 @@ namespace Tests
Test.Assert(v == 3234);
v = SGet2<ClassE, int16>(ce);
Test.Assert(v == 4234);
ClassF cf = scope .();
TestIFaceD(cf);
Test.Assert(cf.mA == 999);
Test.Assert(TestIFaceD2(cf) == 999);
ClassG cg = scope .();
TestIFaceD(cg);
Test.Assert(cg.mA == 999);
Test.Assert(TestIFaceD2(cg) == 999);
}
}
}

View file

@ -71,6 +71,8 @@ namespace Tests
}
}
class ClassB
{
public StructA B { get; set; }
@ -90,6 +92,26 @@ namespace Tests
public override int IVal2 { get => base.IVal2 + 100; }
}
abstract class ClassD
{
public int32 Val { get; set; }
}
class ClassE : ClassD
{
}
static void MethodC<T>(T val) where T : ClassD
{
val.Val = 999;
}
static int MethodD<T>(T val) where T : ClassD
{
return val.Val;
}
[Test]
public static void TestBasics()
{
@ -122,6 +144,11 @@ namespace Tests
ClassB cb2 = cc;
Test.Assert(cb2.IVal == 1);
Test.Assert(cb2.IVal2 == 102);
ClassE ce = scope .();
MethodC(ce);
Test.Assert(ce.Val == 999);
Test.Assert(MethodD(ce) == 999);
}
}
}