Better error information for macros
module test;
import std::io;
macro macro_2(str) {
int a = str;
}
macro macro_1(str) {
macro_2(str);
}
fn int main(String[] args) {
macro_1("Test");
return 0;
}
Emits
2: import std::io;
3:
4: macro macro_2(str) {
5: int a = str;
^^^
(/tmp/test/src/main.c3:5:11) Error: You cannot cast 'String' to 'int'.
But there is no information on where this macro was invoked from.
The error should trace all the way back to the origin. Kind of like so:
2: import std::io;
3:
4: macro macro_2(str) {
5: int a = str;
^^^
(/tmp/test/src/main.c3:5:11) Error: You cannot cast 'String' to 'int'.
6: }
7:
8: macro macro_1(str) {
9: macro_2(str);
^^^^^^^
(/tmp/test/src/main.c3:9:3) Note: Invoked from here.
10: }
11:
12: fn int main(String[] args) {
13: macro_1("Test");
^^^^^^^
(/tmp/test/src/main.c3:13:3) Note: Invoked from here.
I've changed this in dev, please have a try.
Works great, thank you.
Any chance this could also be improved?
module test;
import std::io;
macro @macro_2(#x) {
int a = #x;
}
macro @macro_1(#x) {
@macro_2(#x);
}
fn int main(String[] args) {
@macro_1(TEST);
return 0;
}
2: import std::io;
3:
4: macro @macro_2(#x) {
5: int a = #x;
^^
(/tmp/test/src/main.c3:5:11) Error: 'TEST' could not be found, did you spell it right?
Tracing was missing a bit, try it now.
Better, but I found another case:
module test;
import std::io;
macro void @macro_2(x) {
int a = x;
}
macro void @macro_1(#x) {
@macro_2(#x);
}
fn int main(String[] args) {
@macro_1(TEST);
return 0;
}
6: }
7:
8: macro void @macro_1(#x) {
9: @macro_2(#x);
^^
(/tmp/test/src/main.c3:9:12) Error: 'TEST' could not be found, did you spell it right?
Heh, fixed one side of the if, but not the other... Try it again @cbuttner
That case is fixed, but here's one more:
module test;
struct Foo {
bool a;
int b;
}
fn int main(String[] args) {
mem::new(Foo, {
.test = 1,
});
return 0;
}
555:
556: /**
557: * @require $vacount < 2 : "Too many arguments."
558: * @require $or($vacount == 0, $assignable($vaexpr(0), $Type)) : "The second argument must be an initializer for |
^^^^^^^^^^
(/home/christian/Github/c3c/lib/std/core/mem.c3:558:44) Error: This is not a valid member of 'Foo'.
Thanks! Fixed now @cbuttner
Cool, I'll let you know if I stumble across another case.