1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-09 03:52:19 +02:00

Fixed generic property binding

This commit is contained in:
Brian Fiete 2020-11-21 07:09:15 -08:00
parent f2eb588de3
commit b83bc2c2dc
4 changed files with 30 additions and 23 deletions

View file

@ -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;
}
}