mirror of
https://github.com/beefytech/Beef.git
synced 2025-06-08 19:48:20 +02:00
Fix DoPopulateType_CeCheckEnum
This commit is contained in:
parent
8225643598
commit
aa4f9f7dfa
3 changed files with 41 additions and 7 deletions
|
@ -63,17 +63,23 @@ namespace System
|
|||
public static void FatalError(String msg = "Test fatal error encountered", String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
|
||||
{
|
||||
String failStr = scope .()..AppendF("{} at line {} in {}", msg, line, filePath);
|
||||
Internal.[Friend]Test_Error(failStr);
|
||||
if (Compiler.IsComptime)
|
||||
Internal.FatalError(failStr);
|
||||
else
|
||||
Internal.[Friend]Test_Error(failStr);
|
||||
}
|
||||
|
||||
public static void Assert(bool condition, String error = Compiler.CallerExpression[0], String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum)
|
||||
{
|
||||
if (!condition)
|
||||
{
|
||||
if ((Runtime.CheckAssertError != null) && (Runtime.CheckAssertError(.Test, error, filePath, line) == .Ignore))
|
||||
if ((!Compiler.IsComptime) && (Runtime.CheckAssertError != null) && (Runtime.CheckAssertError(.Test, error, filePath, line) == .Ignore))
|
||||
return;
|
||||
String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath);
|
||||
Internal.[Friend]Test_Error(failStr);
|
||||
if (Compiler.IsComptime)
|
||||
Internal.FatalError(failStr);
|
||||
else
|
||||
Internal.[Friend]Test_Error(failStr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3695,7 +3695,7 @@ void BfModule::DoPopulateType_CeCheckEnum(BfTypeInstance* typeInstance, bool und
|
|||
{
|
||||
if (!typeInstance->IsEnum())
|
||||
return;
|
||||
if ((!underlyingTypeDeferred) && (!typeInstance->IsPayloadEnum()))
|
||||
if (!typeInstance->IsPayloadEnum())
|
||||
return;
|
||||
if ((typeInstance->mCeTypeInfo != NULL) && (typeInstance->mCeTypeInfo->mNext != NULL))
|
||||
return;
|
||||
|
|
|
@ -251,15 +251,23 @@ namespace Tests
|
|||
}
|
||||
}
|
||||
|
||||
[CheckEnum]
|
||||
[CheckPayloadEnum]
|
||||
enum EnumA
|
||||
{
|
||||
case A(int64 aa);
|
||||
case B(float bb);
|
||||
}
|
||||
|
||||
[CheckEnum]
|
||||
enum EnumB
|
||||
{
|
||||
case A = 123;
|
||||
case B = 1000;
|
||||
case C = 1200;
|
||||
}
|
||||
|
||||
[AttributeUsage(.All)]
|
||||
public struct CheckEnumAttribute : Attribute, IComptimeTypeApply
|
||||
public struct CheckPayloadEnumAttribute : Attribute, IComptimeTypeApply
|
||||
{
|
||||
public void ApplyToType(Type type)
|
||||
{
|
||||
|
@ -283,6 +291,26 @@ namespace Tests
|
|||
}
|
||||
}
|
||||
|
||||
[AttributeUsage(.All)]
|
||||
public struct CheckEnumAttribute : Attribute, IComptimeTypeApply
|
||||
{
|
||||
public void ApplyToType(Type type)
|
||||
{
|
||||
int fieldIdx = 0;
|
||||
for (var field in type.GetFields())
|
||||
{
|
||||
switch (fieldIdx)
|
||||
{
|
||||
case 0:
|
||||
Test.Assert(field.Name == "A");
|
||||
Test.Assert(field.FieldType.UnderlyingType == typeof(int64));
|
||||
}
|
||||
fieldIdx++;
|
||||
}
|
||||
Test.Assert(fieldIdx == 3);
|
||||
}
|
||||
}
|
||||
|
||||
const String cTest0 = Compiler.ReadText("Test0.txt");
|
||||
const String cTest1 = new String('A', 12);
|
||||
const uint8[?] cTest0Binary = Compiler.ReadBinary("Test0.txt");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue