From efeb9e627e256d0c7966836c0b3a0247cfd34c27 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Fri, 11 Oct 2024 13:26:22 +0200 Subject: [PATCH] Interfaces not correctly copied with generics #1545. --- releasenotes.md | 1 + src/compiler/copying.c | 1 + test/test_suite/generic/generic_idents.c3t | 1 + test/test_suite/generic/generic_interface.c3t | 31 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 test/test_suite/generic/generic_interface.c3t diff --git a/releasenotes.md b/releasenotes.md index 4721edd1c..55eead461 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -29,6 +29,7 @@ - Improved error message on invalid subscript index type #1535. - Improved error message when declaring a variable `void!`. - Cannot use void as a generic parameter #1546 +- Interfaces not correctly copied with generics #1545 ### Stdlib changes - Remove unintended print of `char[]` as String diff --git a/src/compiler/copying.c b/src/compiler/copying.c index 3df845e07..ea4165c19 100644 --- a/src/compiler/copying.c +++ b/src/compiler/copying.c @@ -941,6 +941,7 @@ Decl *copy_decl(CopyStruct *c, Decl *decl) case DECL_ERASED: break; case DECL_INTERFACE: + copy_decl_type(copy); MACRO_COPY_TYPE_LIST(copy->interfaces); MACRO_COPY_DECL_LIST(copy->methods); MACRO_COPY_DECL_LIST(copy->interface_methods); diff --git a/test/test_suite/generic/generic_idents.c3t b/test/test_suite/generic/generic_idents.c3t index eebc5a6bb..c6c20e595 100644 --- a/test/test_suite/generic/generic_idents.c3t +++ b/test/test_suite/generic/generic_idents.c3t @@ -1,3 +1,4 @@ +// #target: macos-aarch64 module gen(); fn Type mult(Type x) diff --git a/test/test_suite/generic/generic_interface.c3t b/test/test_suite/generic/generic_interface.c3t new file mode 100644 index 000000000..6a9b2ef6f --- /dev/null +++ b/test/test_suite/generic/generic_interface.c3t @@ -0,0 +1,31 @@ +// #target: macos-aarch64 +module base; + +module test(); +import base; +interface Zzz +{ + fn void zzz(MyType t); +} +struct TestStruct (Zzz) +{ + String data; +} +fn void TestStruct.zzz(&self, MyType t) @dynamic { } + +module app; +import test; +fn int main() +{ + TestStruct() ts; + return 0; +} + +/* #expect: app.ll + +define i32 @main() #0 { +entry: + %ts = alloca %TestStruct, align 8 + call void @llvm.memset.p0.i64(ptr align 8 %ts, i8 0, i64 16, i1 false) + ret i32 0 +}