Macro Debugging
Macros expand at compile time, and the generated code is invisible, making debugging somewhat difficult. Cangjie provides two important debugging tools: the command-line option --debug-macro and the macro-internal function diagReport.
When compiling with cjc --debug-macro, the compiler writes the macro-expanded code to a .macrocall file. You can view this file to understand what code the macro actually generated, helping to locate problems.
Inside a macro definition, calling diagReport(DiagReportLevel.ERROR, tokens, message, hint) can output formatted error messages at compile time. The errors output by this function are formatted consistently with native compiler errors, including file location, error level, and hint information.
The example below demonstrates the process of using built-in test macros. In actual development, you can first define a problematic macro, use --debug-macro to view the expansion result, and then use diagReport to report usage errors. Try passing an incorrect expected value to @Expect and observe the test framework's output.