diff --git a/lib/std/core/dstring.c3 b/lib/std/core/dstring.c3 index df4035453..495880c1f 100644 --- a/lib/std/core/dstring.c3 +++ b/lib/std/core/dstring.c3 @@ -331,14 +331,14 @@ fn Char32[] DString.copy_utf32(&self, Allocator allocator) } <* - @require $typeof(str) == String || $typeof(str) == DString : "Expected string or DString" + @require $defined(String s = str) ||| $typeof(str) == DString : "Expected string or DString" *> macro void DString.append_string(&self, str) { - $if $typeof(str) == String: - self.append_bytes(str); - $else + $if $typeof(str) == DString: self.append_string_deprecated(str); + $else + self.append_bytes((String)str); $endif } diff --git a/lib/std/hash/gost/streebog.c3 b/lib/std/hash/gost/streebog.c3 index bc5e411f1..98e491c1b 100644 --- a/lib/std/hash/gost/streebog.c3 +++ b/lib/std/hash/gost/streebog.c3 @@ -159,7 +159,7 @@ fn void Streebog._final_private(&self) @local usz index = self.index >> 3; usz shift = (self.index & 0b111) * 8; - unprocessed_bits_count[0] = self.index * 8; + unprocessed_bits_count[0] = self.index * 8ul; self.message[index] &= ~(ulong.max << shift); self.message[index++] ^= 1ul << shift; if (index < 8) self.message[index..] = {}; diff --git a/releasenotes.md b/releasenotes.md index 692a75b58..b55549085 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -16,6 +16,8 @@ - Compiler crash when using arrays of vectors in lists. #2889 - Fix `list[0].i = 5` when `list[0]` returns a pointer. #2888 - Shadowing not detected for generic declarations #2876 +- Const inline enums would not always implicitly get converted to the underlying type. +- Update to dstring.append_string to take any type converting to String. ## 0.7.9 Change list diff --git a/src/compiler/types.c b/src/compiler/types.c index 4a37cd558..e91f7c5df 100644 --- a/src/compiler/types.c +++ b/src/compiler/types.c @@ -1640,18 +1640,18 @@ bool type_is_scalar(Type *type) Type *type_find_parent_type(Type *type) { ASSERT(type->canonical); + Decl *decl; switch (type->type_kind) { + case TYPE_CONST_ENUM: + decl = type->decl; + return decl->is_substruct ? decl->enums.type_info->type : NULL; case TYPE_TYPEDEF: - { - Decl *decl = type->decl; + decl = type->decl; return decl->is_substruct ? decl->distinct->type : NULL; - } case TYPE_STRUCT: - { - Decl *decl = type->decl; + decl = type->decl; return decl->is_substruct ? decl->strukt.members[0]->type : NULL; - } default: return NULL; } diff --git a/test/test_suite/enumerations/const_enum_inline.c3t b/test/test_suite/enumerations/const_enum_inline.c3t new file mode 100644 index 000000000..a9ebf4866 --- /dev/null +++ b/test/test_suite/enumerations/const_enum_inline.c3t @@ -0,0 +1,21 @@ +// #target: macos-x64 +module test; +enum Foo : const inline String +{ + HELO = "Helo" +} + +fn int main() +{ + Foo f = Foo.HELO; + bool b = $defined(String s = Foo.HELO); + bool c = $defined(String s = f); + bool d = $defined(int i = f); + return 0; +} + +/* #expect: test.ll + + store i8 1, ptr %b, align 1 + store i8 1, ptr %c, align 1 + store i8 0, ptr %d, align 1