1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-08 19:48:20 +02:00

More improvements to conversion operator overloading on typed primitive

This commit is contained in:
Brian Fiete 2022-01-21 07:14:45 -05:00
parent e0077fd4ef
commit 0de32f7b34
2 changed files with 28 additions and 15 deletions

View file

@ -12820,11 +12820,13 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
{ {
// Can do // Can do
} }
else if ((!CanCast(GetFakeTypedValue(underlyingType), returnType, implicitCastFlags)) && else if ((CanCast(GetFakeTypedValue(underlyingType), returnType, implicitCastFlags)) &&
(CanCast(GetFakeTypedValue(returnType), underlyingType, implicitCastFlags))) (!CanCast(GetFakeTypedValue(returnType), underlyingType, implicitCastFlags)))
{ {
doCall = false; // Can do
} }
else
doCall = false;
} }
} }
@ -12844,17 +12846,19 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
doCall = false; doCall = false;
} }
else if ((paramCanCast) && else if ((paramCanCast) &&
(!underlyingType)) (!underlyingCanCast))
{ {
doCall = true; // Can do
} }
else if ((!CanCast(GetFakeTypedValue(underlyingType), paramType, implicitCastFlags)) && else if ((CanCast(GetFakeTypedValue(underlyingType), paramType, implicitCastFlags)) &&
(CanCast(GetFakeTypedValue(paramType), underlyingType, implicitCastFlags))) (!CanCast(GetFakeTypedValue(paramType), underlyingType, implicitCastFlags)))
{ {
// Can do
}
else
doCall = false; doCall = false;
} }
} }
}
if (doCall) if (doCall)
{ {

View file

@ -267,9 +267,9 @@ namespace Tests
} }
} }
enum MyEnum enum MyEnum
{ {
Case0,
Case1, Case1,
Case2, Case2,
Case3 Case3
@ -277,13 +277,14 @@ namespace Tests
enum MyOtherEnum enum MyOtherEnum
{ {
case Zero;
case One; case One;
case Two; case Two;
case Three; case Three;
public static explicit operator MyEnum(Self self) public static explicit operator MyEnum(Self self)
{ {
return .Case2; return .Case1;
} }
} }
@ -572,9 +573,17 @@ namespace Tests
int32 b = a + 100; int32 b = a + 100;
Test.Assert(b == 223); Test.Assert(b == 223);
MyOtherEnum moe = .One; MyOtherEnum moe = .Zero;
MyEnum me = (MyEnum)moe; MyEnum me = (MyEnum)moe;
Test.Assert(me == .Case2); Test.Assert(me == .Case1);
Test.Assert(moe == 0);
moe = .Two;
int32 i = (int32)moe;
Test.Assert(i == 2);
uint32 u = (uint32)moe;
Test.Assert(u == 2);
// //
{ {