mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 12:32:20 +02:00
Improved casting of typed primitives with conversion operators
This commit is contained in:
parent
83bed6b004
commit
633424b6da
2 changed files with 26 additions and 16 deletions
|
@ -12818,33 +12818,43 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
|||
else if ((returnCanCast) &&
|
||||
(!underlyingCanCast))
|
||||
{
|
||||
doCall = true;
|
||||
// Can do
|
||||
}
|
||||
else if ((CanCast(GetFakeTypedValue(underlyingType), returnType, implicitCastFlags)) &&
|
||||
(!CanCast(GetFakeTypedValue(returnType), underlyingType)))
|
||||
else if ((!CanCast(GetFakeTypedValue(underlyingType), returnType, implicitCastFlags)) &&
|
||||
(CanCast(GetFakeTypedValue(returnType), underlyingType, implicitCastFlags)))
|
||||
{
|
||||
doCall = true;
|
||||
}
|
||||
else
|
||||
doCall = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check underlying->typedPrimitive cast
|
||||
if ((explicitCast) && (toType->IsTypedPrimitive()))
|
||||
{
|
||||
auto underlyingType = toType->GetUnderlyingType();
|
||||
if ((paramType != underlyingType) && (CanCast(typedVal, underlyingType, (BfCastFlags)(castFlags | BfCastFlags_NoConversionOperator))))
|
||||
if ((paramType != underlyingType) &&
|
||||
(CanCast(typedVal, underlyingType, (BfCastFlags)(castFlags | BfCastFlags_NoConversionOperator))))
|
||||
{
|
||||
if ((CanCast(GetFakeTypedValue(underlyingType), paramType, implicitCastFlags)) &&
|
||||
(!CanCast(GetFakeTypedValue(paramType), underlyingType, implicitCastFlags)))
|
||||
float underlyingCanCast = CanCast(typedVal, underlyingType, implicitCastFlags);
|
||||
float paramCanCast = CanCast(typedVal, paramType, implicitCastFlags);
|
||||
|
||||
if ((underlyingType) &&
|
||||
(!paramCanCast))
|
||||
{
|
||||
doCall = false;
|
||||
}
|
||||
else if ((paramCanCast) &&
|
||||
(!underlyingType))
|
||||
{
|
||||
doCall = true;
|
||||
}
|
||||
else
|
||||
else if ((!CanCast(GetFakeTypedValue(underlyingType), paramType, implicitCastFlags)) &&
|
||||
(CanCast(GetFakeTypedValue(paramType), underlyingType, implicitCastFlags)))
|
||||
{
|
||||
doCall = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (doCall)
|
||||
{
|
||||
|
|
|
@ -283,7 +283,7 @@ namespace Tests
|
|||
|
||||
public static explicit operator MyEnum(Self self)
|
||||
{
|
||||
return .Case1;
|
||||
return .Case2;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -572,9 +572,9 @@ namespace Tests
|
|||
int32 b = a + 100;
|
||||
Test.Assert(b == 223);
|
||||
|
||||
MyOtherEnum myEnum = .One;
|
||||
MyEnum me = (MyEnum)myEnum;
|
||||
Test.Assert(me == .Case1);
|
||||
MyOtherEnum moe = .One;
|
||||
MyEnum me = (MyEnum)moe;
|
||||
Test.Assert(me == .Case2);
|
||||
|
||||
//
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue