diff --git a/releasenotes.md b/releasenotes.md index eb7ae66c6..7c87c4e7f 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -66,6 +66,7 @@ - Fix `Formatter.print` returning incorrect size. - A distinct type based on an array would yield .len == 0 - Overloading addition with a pointer would not work. +- Copying const enums and regular enums incorrect #2313. ### Stdlib changes - Improve contract for readline. #2280 diff --git a/src/compiler/copying.c b/src/compiler/copying.c index bee9dd8a4..4b8760b1b 100644 --- a/src/compiler/copying.c +++ b/src/compiler/copying.c @@ -1089,16 +1089,16 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) return copy; case DECL_ENUM_CONSTANT: if (copy->enum_constant.is_raw) - { - MACRO_COPY_EXPR_LIST(copy->enum_constant.associated); - } - else { if (copy->resolve_status != RESOLVE_DONE) { MACRO_COPY_EXPR(copy->enum_constant.value); } } + else + { + MACRO_COPY_EXPR_LIST(copy->enum_constant.associated); + } break; case DECL_TYPEDEF: copy_decl_type(copy); diff --git a/test/test_suite/enumerations/enum_copy.c3t b/test/test_suite/enumerations/enum_copy.c3t new file mode 100644 index 000000000..9dbef9d62 --- /dev/null +++ b/test/test_suite/enumerations/enum_copy.c3t @@ -0,0 +1,20 @@ +module generic_module_enum{N}; + +enum Foo : char (String s) +{ + BAR = "bar", +} + +module generic_module_enum_test; +import generic_module_enum; + +fn void test() + +{ + Foo{3} foo; +} + +fn void main() +{ + test(); +} \ No newline at end of file