mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48: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
|
@ -3799,7 +3799,6 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
||||||
auto result = LookupField(targetSrc, BfTypedValue(target.mValue, iface), fieldName, flags);
|
auto result = LookupField(targetSrc, BfTypedValue(target.mValue, iface), fieldName, flags);
|
||||||
if ((result) || (mPropDef != NULL))
|
if ((result) || (mPropDef != NULL))
|
||||||
{
|
{
|
||||||
//BindGenericType(targetSrc, iface);
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3915,6 +3914,9 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
||||||
BfFieldDef* matchedField = NULL;
|
BfFieldDef* matchedField = NULL;
|
||||||
while (nextField != NULL)
|
while (nextField != NULL)
|
||||||
{
|
{
|
||||||
|
if ((flags & BfLookupFieldFlag_BindOnly) != 0)
|
||||||
|
break;
|
||||||
|
|
||||||
auto field = nextField;
|
auto field = nextField;
|
||||||
nextField = nextField->mNextWithSameName;
|
nextField = nextField->mNextWithSameName;
|
||||||
|
|
||||||
|
@ -4357,6 +4359,11 @@ BfTypedValue BfExprEvaluator::LookupField(BfAstNode* targetSrc, BfTypedValue tar
|
||||||
|
|
||||||
mModule->SetElementType(targetSrc, BfSourceElementType_Method);
|
mModule->SetElementType(targetSrc, BfSourceElementType_Method);
|
||||||
|
|
||||||
|
if ((prop->mName == "Track") && (mModule->mCurMethodInstance->mMethodDef->mName == "Add"))
|
||||||
|
{
|
||||||
|
NOP;
|
||||||
|
}
|
||||||
|
|
||||||
mPropSrc = targetSrc;
|
mPropSrc = targetSrc;
|
||||||
mPropDef = prop;
|
mPropDef = prop;
|
||||||
mPropCheckedKind = checkedKind;
|
mPropCheckedKind = checkedKind;
|
||||||
|
@ -8515,7 +8522,7 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
|
||||||
if ((lookupType->IsGenericParam()) && (!mResult.mType->IsGenericParam()))
|
if ((lookupType->IsGenericParam()) && (!mResult.mType->IsGenericParam()))
|
||||||
{
|
{
|
||||||
// Try to lookup from generic binding
|
// 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)
|
if (mPropDef != NULL)
|
||||||
{
|
{
|
||||||
mOrigPropTarget = lookupVal;
|
mOrigPropTarget = lookupVal;
|
||||||
|
@ -8532,7 +8539,6 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
|
||||||
SizedArray<BfTypeInstance*, 8> searchConstraints;
|
SizedArray<BfTypeInstance*, 8> searchConstraints;
|
||||||
for (auto ifaceConstraint : genericParamInst->mInterfaceConstraints)
|
for (auto ifaceConstraint : genericParamInst->mInterfaceConstraints)
|
||||||
{
|
{
|
||||||
//if (std::find(searchConstraints.begin(), searchConstraints.end(), ifaceConstraint) == searchConstraints.end())
|
|
||||||
if (!searchConstraints.Contains(ifaceConstraint))
|
if (!searchConstraints.Contains(ifaceConstraint))
|
||||||
{
|
{
|
||||||
searchConstraints.push_back(ifaceConstraint);
|
searchConstraints.push_back(ifaceConstraint);
|
||||||
|
@ -8540,7 +8546,6 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
|
||||||
for (auto& innerIFaceEntry : ifaceConstraint->mInterfaces)
|
for (auto& innerIFaceEntry : ifaceConstraint->mInterfaces)
|
||||||
{
|
{
|
||||||
auto innerIFace = innerIFaceEntry.mInterfaceType;
|
auto innerIFace = innerIFaceEntry.mInterfaceType;
|
||||||
//if (std::find(searchConstraints.begin(), searchConstraints.end(), innerIFace) == searchConstraints.end())
|
|
||||||
if (!searchConstraints.Contains(innerIFace))
|
if (!searchConstraints.Contains(innerIFace))
|
||||||
{
|
{
|
||||||
searchConstraints.push_back(innerIFace);
|
searchConstraints.push_back(innerIFace);
|
||||||
|
@ -8553,7 +8558,6 @@ void BfExprEvaluator::LookupQualifiedName(BfAstNode* nameNode, BfIdentifierNode*
|
||||||
BfPropertyDef* prevDef = NULL;
|
BfPropertyDef* prevDef = NULL;
|
||||||
for (auto ifaceConstraint : searchConstraints)
|
for (auto ifaceConstraint : searchConstraints)
|
||||||
{
|
{
|
||||||
//auto lookupVal = mModule->GetDefaultTypedValue(ifaceConstraint, origResult.IsAddr());
|
|
||||||
BfTypedValue lookupVal = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), ifaceConstraint);
|
BfTypedValue lookupVal = BfTypedValue(mModule->mBfIRBuilder->GetFakeVal(), ifaceConstraint);
|
||||||
|
|
||||||
mResult = LookupField(nameRight, lookupVal, fieldName);
|
mResult = LookupField(nameRight, lookupVal, fieldName);
|
||||||
|
@ -15687,11 +15691,8 @@ BfTypedValue BfExprEvaluator::GetResult(bool clearResult, bool resolveGenericTyp
|
||||||
if (!matchedMethod->mIsStatic)
|
if (!matchedMethod->mIsStatic)
|
||||||
{
|
{
|
||||||
auto owner = methodInstance.mMethodInstance->GetOwner();
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -309,7 +309,8 @@ enum BfLookupFieldFlags
|
||||||
BfLookupFieldFlag_None = 0,
|
BfLookupFieldFlag_None = 0,
|
||||||
BfLookupFieldFlag_IsImplicitThis = 1,
|
BfLookupFieldFlag_IsImplicitThis = 1,
|
||||||
BfLookupFieldFlag_CheckingOuter = 2,
|
BfLookupFieldFlag_CheckingOuter = 2,
|
||||||
BfLookupFieldFlag_IgnoreProtection = 4
|
BfLookupFieldFlag_IgnoreProtection = 4,
|
||||||
|
BfLookupFieldFlag_BindOnly = 8
|
||||||
};
|
};
|
||||||
|
|
||||||
enum BfUnaryOpFlags
|
enum BfUnaryOpFlags
|
||||||
|
|
|
@ -3762,6 +3762,7 @@ void BfModule::ResolveConstField(BfTypeInstance* typeInstance, BfFieldInstance*
|
||||||
fieldType = fieldInstance->GetResolvedType();
|
fieldType = fieldInstance->GetResolvedType();
|
||||||
if ((fieldType == NULL) || (fieldType->IsVar()))
|
if ((fieldType == NULL) || (fieldType->IsVar()))
|
||||||
{
|
{
|
||||||
|
SetAndRestoreValue<bool> prevIgnoreWrite(mBfIRBuilder->mIgnoreWrites, true);
|
||||||
AssertErrorState();
|
AssertErrorState();
|
||||||
// Default const type is 'int'
|
// Default const type is 'int'
|
||||||
BfTypedValue initValue = GetDefaultTypedValue(GetPrimitiveType(BfTypeCode_IntPtr));
|
BfTypedValue initValue = GetDefaultTypedValue(GetPrimitiveType(BfTypeCode_IntPtr));
|
||||||
|
|
|
@ -9950,7 +9950,7 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
{
|
{
|
||||||
for (auto iface : genericParamInst->mInterfaceConstraints)
|
for (auto iface : genericParamInst->mInterfaceConstraints)
|
||||||
if (TypeIsSubTypeOf(iface, toType->ToTypeInstance()))
|
if (TypeIsSubTypeOf(iface, toType->ToTypeInstance()))
|
||||||
return GetDefaultValue(toType);
|
return mBfIRBuilder->GetFakeVal();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (genericParamInst->mTypeConstraint != NULL)
|
if (genericParamInst->mTypeConstraint != NULL)
|
||||||
|
@ -9960,12 +9960,16 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
{
|
{
|
||||||
// Enum->int
|
// Enum->int
|
||||||
if ((explicitCast) && (toType->IsInteger()))
|
if ((explicitCast) && (toType->IsInteger()))
|
||||||
return GetDefaultValue(toType);
|
return typedVal.mValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto defaultFromValue = GetDefaultTypedValue(genericParamInst->mTypeConstraint);
|
BfTypedValue fromTypedValue;
|
||||||
auto result = CastToValue(srcNode, defaultFromValue, toType, (BfCastFlags)(castFlags | BfCastFlags_SilentFail));
|
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 (result)
|
||||||
{
|
{
|
||||||
if ((genericParamInst->mTypeConstraint->IsDelegate()) && (toType->IsDelegate()))
|
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->IsInstanceOf(mCompiler->mFunctionTypeDef)) ||
|
||||||
(genericParamInst->mTypeConstraint->IsObjectOrInterface()))))
|
(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)
|
if ((genericParamInst->mGenericParamFlags & BfGenericParamFlag_Enum) != 0)
|
||||||
{
|
{
|
||||||
return mBfIRBuilder->GetFakeVal();
|
return typedVal.mValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue