diff --git a/BeefLibs/corlib/src/Test.bf b/BeefLibs/corlib/src/Test.bf index e82dc6db..dbf86b2b 100644 --- a/BeefLibs/corlib/src/Test.bf +++ b/BeefLibs/corlib/src/Test.bf @@ -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); } } } diff --git a/IDEHelper/Compiler/BfModuleTypeUtils.cpp b/IDEHelper/Compiler/BfModuleTypeUtils.cpp index 77498346..d85f8445 100644 --- a/IDEHelper/Compiler/BfModuleTypeUtils.cpp +++ b/IDEHelper/Compiler/BfModuleTypeUtils.cpp @@ -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; diff --git a/IDEHelper/Tests/src/Comptime.bf b/IDEHelper/Tests/src/Comptime.bf index 66887837..9b3cb52d 100644 --- a/IDEHelper/Tests/src/Comptime.bf +++ b/IDEHelper/Tests/src/Comptime.bf @@ -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");