mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-10 04:22:20 +02:00
Allow 'public static int operator implicit(Self self);'
This commit is contained in:
parent
fa251b3439
commit
94944082eb
3 changed files with 23 additions and 0 deletions
|
@ -25171,6 +25171,14 @@ void BfModule::DoMethodDeclaration(BfMethodDeclaration* methodDeclaration, bool
|
||||||
{
|
{
|
||||||
isError = false;
|
isError = false;
|
||||||
}
|
}
|
||||||
|
else if (mCurTypeInstance->IsEnum())
|
||||||
|
{
|
||||||
|
if (((methodInstance->mReturnType == typeInstance) && (methodInstance->GetParamType(0)->IsInteger())) ||
|
||||||
|
((methodInstance->mReturnType->IsInteger()) && (methodInstance->GetParamType(0) == typeInstance)))
|
||||||
|
{
|
||||||
|
isError = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14672,6 +14672,11 @@ BfIRValue BfModule::CastToValue(BfAstNode* srcNode, BfTypedValue typedVal, BfTyp
|
||||||
{
|
{
|
||||||
typedVal = LoadValue(typedVal);
|
typedVal = LoadValue(typedVal);
|
||||||
auto convTypedValue = BfTypedValue(typedVal.mValue, fromType->GetUnderlyingType());
|
auto convTypedValue = BfTypedValue(typedVal.mValue, fromType->GetUnderlyingType());
|
||||||
|
if ((fromType->IsEnum()) && (convTypedValue.mType->IsVoid()) && (methodMatcher.mBestRawMethodInstance != NULL))
|
||||||
|
{
|
||||||
|
if (methodMatcher.mBestRawMethodInstance)
|
||||||
|
convTypedValue = GetDefaultTypedValue(methodMatcher.mBestRawMethodInstance->mReturnType);
|
||||||
|
}
|
||||||
return CastToValue(srcNode, convTypedValue, toType, (BfCastFlags)(castFlags & ~BfCastFlags_Explicit), NULL);
|
return CastToValue(srcNode, convTypedValue, toType, (BfCastFlags)(castFlags & ~BfCastFlags_Explicit), NULL);
|
||||||
}
|
}
|
||||||
else if (toType->IsTypedPrimitive())
|
else if (toType->IsTypedPrimitive())
|
||||||
|
|
|
@ -102,6 +102,13 @@ namespace Tests
|
||||||
SDL_BUTTON_LMASK = (1u << ((SDL_BUTTON_LEFT.Underlying) - 1)),
|
SDL_BUTTON_LMASK = (1u << ((SDL_BUTTON_LEFT.Underlying) - 1)),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum EnumL
|
||||||
|
{
|
||||||
|
case A;
|
||||||
|
|
||||||
|
public static int operator implicit(Self self);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
static void TestBasic()
|
static void TestBasic()
|
||||||
{
|
{
|
||||||
|
@ -249,6 +256,9 @@ namespace Tests
|
||||||
|
|
||||||
Test.Assert((int)EnumK.SDL_BUTTON_LMASK == 1);
|
Test.Assert((int)EnumK.SDL_BUTTON_LMASK == 1);
|
||||||
Test.Assert(typeof(EnumK).Size == 8);
|
Test.Assert(typeof(EnumK).Size == 8);
|
||||||
|
|
||||||
|
EnumL el = .A;
|
||||||
|
Test.Assert(el == 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue