Closed
Description
Minimal code (you may need to add some imports, because I carved this snippet from another code):
module test;
import std::io;
struct MyFoo {
uint idx;
}
struct MyFooIter {
MyFoo* parent;
uint idx;
}
macro MyFooIter MyFoo.iter(&self) {
return (MyFooIter){.parent = self};
}
macro MyFoo*! MyFooIter.next(&self) {
MyFoo foo = {.idx = 999};
// expected to always fail
if (!mem::equals(&foo, self.parent, MyFoo.sizeof)) {
return IoError.GENERAL_ERROR?;
}
return self.parent;
}
module test @test;
fn void test_myfoo()
{
MyFoo foo;
MyFooIter iter = foo.iter();
// This will compile and blow up with GENERAL_ERROR (expected)
// iter.next()!!;
// This doesn't compile with weird error
test::@error(iter.next(), IoError.GENERAL_ERROR);
}
Error:
416: macro bool equals(a, b, isz len = -1, usz $align = 0)
417: {
418: $if !$align:
419: $align = $typeof(a[0]).alignof;
^^^^^^
(/home/ubertrader/code/c3c/lib/std/core/mem.c3:419:3) Error: Compile time variables may only be modified in the scope they are defined in.
70: macro MyFoo*! MyFooIter.next(&self) {
71: MyFoo foo = {.idx = 999};
72:
73: if (!mem::equals(&foo, self.parent, MyFoo.sizeof)) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(/home/ubertrader/code/c3tools/test/c3tools/lsp/test_symhash.c3:73:10) Note: Inlined from here.
88: *>
89: macro @error(#funcresult, anyfault error_expected)
90: {
91: if (catch err = #funcresult) {
^^^^^^^^^^^
(/home/ubertrader/code/c3c/lib/std/core/test.c3:91:18) Note: Inlined from here.
442: $Type = uint;
443: $case 8:
444: $default:
445: $Type = ulong;
^^^^^
(/home/ubertrader/code/c3c/lib/std/core/mem.c3:445:4) Error: Compile time variables may only be modified in the scope they are defined in.
70: macro MyFoo*! MyFooIter.next(&self) {
71: MyFoo foo = {.idx = 999};
72:
73: if (!mem::equals(&foo, self.parent, MyFoo.sizeof)) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
(/home/ubertrader/code/c3tools/test/c3tools/lsp/test_symhash.c3:73:10) Note: Inlined from here.
88: *>
89: macro @error(#funcresult, anyfault error_expected)
90: {
91: if (catch err = #funcresult) {
^^^^^^^^^^^
(/home/ubertrader/code/c3c/lib/std/core/test.c3:91:18) Note: Inlined from here.
444: $default:
445: $Type = ulong;
446: $endswitch
447: var $step = $Type.sizeof;
^^^^^
(/home/ubertrader/code/c3c/lib/std/core/mem.c3:447:14) Error: You need to assign a type to '$Type' before using it.
C3 Compiler Version: 0.6.8 (Pre-release, Feb 20 2025 11:29:04)
Installed directory: /home/ubertrader/code/c3c/build/
Git Hash: e97ff1ce21bddc6dc4d406b42c983f35d16982fc
Backends: LLVM
LLVM version: 18.1.8
LLVM default target: x86_64-pc-linux-gnu