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

Fix DoPopulateType_CeCheckEnum

This commit is contained in:
Brian Fiete 2024-04-28 11:29:49 -04:00
parent 8225643598
commit aa4f9f7dfa
3 changed files with 41 additions and 7 deletions

View file

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

View file

@ -3692,10 +3692,10 @@ void BfModule::DoPopulateType_FinishEnum(BfTypeInstance* typeInstance, bool unde
}
void BfModule::DoPopulateType_CeCheckEnum(BfTypeInstance* typeInstance, bool underlyingTypeDeferred)
{
{
if (!typeInstance->IsEnum())
return;
if ((!underlyingTypeDeferred) && (!typeInstance->IsPayloadEnum()))
if (!typeInstance->IsPayloadEnum())
return;
if ((typeInstance->mCeTypeInfo != NULL) && (typeInstance->mCeTypeInfo->mNext != NULL))
return;

View file

@ -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");