mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 03:28:20 +02:00
Fixed generic property binding
This commit is contained in:
parent
f2eb588de3
commit
b83bc2c2dc
4 changed files with 30 additions and 23 deletions
|
@ -3798,8 +3798,7 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
|||
{
|
||||
auto result = LookupField(targetSrc, BfTypedValue(target.mValue, iface), fieldName, flags);
|
||||
if ((result) || (mPropDef != NULL))
|
||||
{
|
||||
//BindGenericType(targetSrc, iface);
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
@ -3899,7 +3898,7 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
|||
|
||||
bool isBaseLookup = false;
|
||||
while (curCheckType != NULL)
|
||||
{
|
||||
{
|
||||
curCheckType->mTypeDef->PopulateMemberSets();
|
||||
BfFieldDef* nextField = NULL;
|
||||
BfMemberSetEntry* entry;
|
||||
|
@ -3915,6 +3914,9 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
|||
BfFieldDef* matchedField = NULL;
|
||||
while (nextField != NULL)
|
||||
{
|
||||
if ((flags & BfLookupFieldFlag_BindOnly) != 0)
|
||||
break;
|
||||
|
||||
auto field = nextField;
|
||||
nextField = nextField->mNextWithSameName;
|
||||
|
||||
|
@ -4357,6 +4359,11 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
|||
|
||||
mModule->SetElementType(targetSrc, BfSourceElementType_Method);
|
||||
|
||||
if ((prop->mName == "Track") && (mModule->mCurMethodInstance->mMethodDef->mName == "Add"))
|
||||
{
|
||||
NOP;
|
||||
}
|
||||
|
||||
mPropSrc = targetSrc;
|
||||
mPropDef = prop;
|
||||
mPropCheckedKind = checkedKind;
|
||||
|
@ -8515,7 +8522,7 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
|
|||
if ((lookupType->IsGenericParam()) && (!mResult.mType->IsGenericParam()))
|
||||
{
|
||||
// Try to lookup from generic binding
|
||||
mResult = LookupField(nameRight, BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), lookupType), fieldName);
|
||||
mResult = LookupField(nameRight, BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), lookupType), fieldName, BfLookupFieldFlag_BindOnly);
|
||||
if (mPropDef != NULL)
|
||||
{
|
||||
mOrigPropTarget = lookupVal;
|
||||
|
@ -8531,16 +8538,14 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
|
|||
auto genericParamInst = mModule->GetGenericParamInstance((BfGenericParamType*)lookupType);
|
||||
SizedArray<BfTypeInstance*, 8> searchConstraints;
|
||||
for (auto ifaceConstraint : genericParamInst->mInterfaceConstraints)
|
||||
{
|
||||
//if (std::find(searchConstraints.begin(), searchConstraints.end(), ifaceConstraint) == searchConstraints.end())
|
||||
{
|
||||
if (!searchConstraints.Contains(ifaceConstraint))
|
||||
{
|
||||
searchConstraints.push_back(ifaceConstraint);
|
||||
|
||||
for (auto& innerIFaceEntry : ifaceConstraint->mInterfaces)
|
||||
{
|
||||
auto innerIFace = innerIFaceEntry.mInterfaceType;
|
||||
//if (std::find(searchConstraints.begin(), searchConstraints.end(), innerIFace) == searchConstraints.end())
|
||||
auto innerIFace = innerIFaceEntry.mInterfaceType;
|
||||
if (!searchConstraints.Contains(innerIFace))
|
||||
{
|
||||
searchConstraints.push_back(innerIFace);
|
||||
|
@ -8552,8 +8557,7 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
|
|||
BfTypedValue prevTarget;
|
||||
BfPropertyDef* prevDef = NULL;
|
||||
for (auto ifaceConstraint : searchConstraints)
|
||||
{
|
||||
//auto lookupVal = mModule->GetDefaultTypedValue(ifaceConstraint, origResult.IsAddr());
|
||||
{
|
||||
BfTypedValue lookupVal = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), ifaceConstraint);
|
||||
|
||||
mResult = LookupField(nameRight, lookupVal, fieldName);
|
||||
|
@ -15687,12 +15691,9 @@ BfTypedValue BfExprEvaluator::GetResult(bool clearResult, bool resolveGenericTyp
|
|||
if (!matchedMethod->mIsStatic)
|
||||
{
|
||||
auto owner = methodInstance.mMethodInstance->GetOwner();
|
||||
if (mPropTarget.mType != owner)
|
||||
if ((mPropTarget.mValue.IsFake()) && (!mOrigPropTarget.mValue.IsFake()))
|
||||
{
|
||||
/*if (owner->IsInterface())
|
||||
mPropTarget = mModule->Cast(mPropSrc, mPropTarget, owner);
|
||||
else */ if (mPropDefBypassVirtual)
|
||||
mPropTarget = mModule->Cast(mPropSrc, mOrigPropTarget, owner);
|
||||
mPropTarget = mModule->Cast(mPropSrc, mOrigPropTarget, owner);
|
||||
}
|
||||
|
||||
if ((mPropGetMethodFlags & BfGetMethodInstanceFlag_DisableObjectAccessChecks) == 0)
|
||||
|
@ -17976,7 +17977,7 @@ void BfExprEvaluator::Visit(BfIndexerExpression* indexerExpr)
|
|||
mModule->Fail(StrFormat("Expected %d fewer indices", -indexDiff), indexerExpr->mTarget);
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
mPropSrc = indexerExpr->mOpenBracket;
|
||||
mPropDef = foundProp;
|
||||
if (foundProp->mIsStatic)
|
||||
|
|
|
@ -309,7 +309,8 @@ enum BfLookupFieldFlags
|
|||
BfLookupFieldFlag_None = 0,
|
||||
BfLookupFieldFlag_IsImplicitThis = 1,
|
||||
BfLookupFieldFlag_CheckingOuter = 2,
|
||||
BfLookupFieldFlag_IgnoreProtection = 4
|
||||
BfLookupFieldFlag_IgnoreProtection = 4,
|
||||
BfLookupFieldFlag_BindOnly = 8
|
||||
};
|
||||
|
||||
enum BfUnaryOpFlags
|
||||
|
|
|
@ -3762,6 +3762,7 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance*
|
|||
fieldType = fieldInstance->GetResolvedType();
|
||||
if ((fieldType == NULL) || (fieldType->IsVar()))
|
||||
{
|
||||
SetAndRestoreValue<bool> prevIgnoreWrite(mBfIRBuilder->mIgnoreWrites, true);
|
||||
AssertErrorState();
|
||||
// Default const type is 'int'
|
||||
BfTypedValue initValue = GetDefaultTypedValue(GetPrimitiveType(BfTypeCode_IntPtr));
|
||||
|
|
|
@ -9950,7 +9950,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
{
|
||||
for (auto iface : genericParamInst->mInterfaceConstraints)
|
||||
if (TypeIsSubTypeOf(iface, toType->ToTypeInstance()))
|
||||
return GetDefaultValue(toType);
|
||||
return mBfIRBuilder->GetFakeVal();
|
||||
}
|
||||
|
||||
if (genericParamInst->mTypeConstraint != NULL)
|
||||
|
@ -9960,12 +9960,16 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
{
|
||||
// Enum->int
|
||||
if ((explicitCast) && (toType->IsInteger()))
|
||||
return GetDefaultValue(toType);
|
||||
return typedVal.mValue;
|
||||
}
|
||||
|
||||
auto defaultFromValue = GetDefaultTypedValue(genericParamInst->mTypeConstraint);
|
||||
auto result = CastToValue(srcNode, defaultFromValue, toType, (BfCastFlags)(castFlags | BfCastFlags_SilentFail));
|
||||
BfTypedValue fromTypedValue;
|
||||
if (typedVal.mKind == BfTypedValueKind_GenericConstValue)
|
||||
fromTypedValue = GetDefaultTypedValue(genericParamInst->mTypeConstraint);
|
||||
else
|
||||
fromTypedValue = BfTypedValue(mBfIRBuilder->GetFakeVal(), genericParamInst->mTypeConstraint, genericParamInst->mTypeConstraint->IsValueType());
|
||||
|
||||
auto result = CastToValue(srcNode, fromTypedValue, toType, (BfCastFlags)(castFlags | BfCastFlags_SilentFail));
|
||||
if (result)
|
||||
{
|
||||
if ((genericParamInst->mTypeConstraint->IsDelegate()) && (toType->IsDelegate()))
|
||||
|
@ -9987,7 +9991,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
(genericParamInst->mTypeConstraint->IsInstanceOf(mCompiler->mFunctionTypeDef)) ||
|
||||
(genericParamInst->mTypeConstraint->IsObjectOrInterface()))))
|
||||
{
|
||||
return GetDefaultValue(toType);
|
||||
return typedVal.mValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9995,7 +9999,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
{
|
||||
if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Enum) != 0)
|
||||
{
|
||||
return mBfIRBuilder->GetFakeVal();
|
||||
return typedVal.mValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue