You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
⚠️ The compiler encountered an unexpected error: "Should be unreachable".
- Function: sema_trace_decl_liveness(...)
- Source file: /build/5wc7gif967l539vxk1vly1prqrcfc0q3-source/src/compiler/sema_liveness.c:625
🙏 Please consider taking the time to file an issue on GitHub, so that we can get it fixed:
https://github.com/c3lang/c3c/issues/new so that we can get it fixed.
Minimum reproducable example would be as follow
importstd::io;
structContainer {
int[] items;
}
macrointContainer.get(&this, uszi) @operator([]) {
returnthis.items[i];
}
aliasProcGetItem=fnint(usz);
fnvoidprocess(intinput, ProcGetItemgetter) {
io::printfn("%d", getter(1) +getter(2) +input);
}
fnvoidmain() {
Containerc= {
.items= { 2, 3, 4, 5 }
};
// &c.get is not an fn, this should produce compile errorprocess(10, &c.get);
}
And also, unrelated to the error above but I want to ask the correct way to write this. I have a function that take a getter as parameter, I also have a container providing get operator. How to connect these two without the function depending on the container implementation?
The text was updated successfully, but these errors were encountered:
hucancode
changed the title
Compiler encountered an unexpected error, mistakenly pass a macro instead of function pointer
Unexpected compiler error when mistakenly pass a macro instead of function pointer
Mar 16, 2025
I can't find an equivalent in C, here is the C++ version of my intention. container.cpp only care about managing it's data. process.cpp only care about the business, they allow caller to pass an adder and it will call that while doing business.
// container.cpp
#include<vector>structContainer {
std::vector<int> items;
};
voidcontainer_add(Container* c, int value) {
c->items.push_back(value);
}
// process.cpp
#include<iostream>template<typename Adder>
voidprocess(Adder adder, int a) {
adder(a);
std::cout << a <<" was just added to some container and I don't care about its implementation" << std::endl;
// continue to the main business
}
// main.cpp
#include<functional>intmain() {
Container my_container;
auto adder = [&my_container](int value) {
container_add(&my_container, value);
};
process(adder, 1);
process(adder, 2);
for (int item : my_container.items) {
std::cout << item << "";
}
return0;
}
I am writing some code and get the error
Minimum reproducable example would be as follow
And also, unrelated to the error above but I want to ask the correct way to write this. I have a function that take a getter as parameter, I also have a container providing get operator. How to connect these two without the function depending on the container implementation?
The text was updated successfully, but these errors were encountered: