1
0
Fork 0
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:
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,6 +63,9 @@ namespace System
public static void FatalError(String msg = "Test fatal error encountered", String filePath = Compiler.CallerFilePath, int line = Compiler.CallerLineNum) 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); String failStr = scope .()..AppendF("{} at line {} in {}", msg, line, filePath);
if (Compiler.IsComptime)
Internal.FatalError(failStr);
else
Internal.[Friend]Test_Error(failStr); Internal.[Friend]Test_Error(failStr);
} }
@ -70,9 +73,12 @@ namespace System
{ {
if (!condition) 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; return;
String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath); String failStr = scope .()..AppendF("Assert failed: {} at line {} in {}", error, line, filePath);
if (Compiler.IsComptime)
Internal.FatalError(failStr);
else
Internal.[Friend]Test_Error(failStr); Internal.[Friend]Test_Error(failStr);
} }
} }

View file

@ -3695,7 +3695,7 @@ void BfModule::DoPopulateType_CeCheckEnum(BfTypeInstance* typeInstance, bool und
{ {
if (!typeInstance->IsEnum()) if (!typeInstance->IsEnum())
return; return;
if ((!underlyingTypeDeferred) && (!typeInstance->IsPayloadEnum())) if (!typeInstance->IsPayloadEnum())
return; return;
if ((typeInstance->mCeTypeInfo != NULL) && (typeInstance->mCeTypeInfo->mNext != NULL)) if ((typeInstance->mCeTypeInfo != NULL) && (typeInstance->mCeTypeInfo->mNext != NULL))
return; return;

View file

@ -251,15 +251,23 @@ namespace Tests
} }
} }
[CheckEnum] [CheckPayloadEnum]
enum EnumA enum EnumA
{ {
case A(int64 aa); case A(int64 aa);
case B(float bb); case B(float bb);
} }
[CheckEnum]
enum EnumB
{
case A = 123;
case B = 1000;
case C = 1200;
}
[AttributeUsage(.All)] [AttributeUsage(.All)]
public struct CheckEnumAttribute : Attribute, IComptimeTypeApply public struct CheckPayloadEnumAttribute : Attribute, IComptimeTypeApply
{ {
public void ApplyToType(Type type) 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 cTest0 = Compiler.ReadText("Test0.txt");
const String cTest1 = new String('A', 12); const String cTest1 = new String('A', 12);
const uint8[?] cTest0Binary = Compiler.ReadBinary("Test0.txt"); const uint8[?] cTest0Binary = Compiler.ReadBinary("Test0.txt");