@@ -28,9 +28,15 @@ fn (mut c Checker) add_instruction_for_result_type() {
2828 c.table.cur_fn.return_type_pos)
2929}
3030
31- fn (mut c Checker) warn (s string , pos token.Pos) {
31+ @[params]
32+ pub struct MessageOptions {
33+ pub :
34+ call_stack []errors.CallStackItem
35+ }
36+
37+ fn (mut c Checker) warn (s string , pos token.Pos, options MessageOptions) {
3238 allow_warnings := ! (c.pref.is_prod || c.pref.warns_are_errors) // allow warnings only in dev builds
33- c.warn_or_error (s, pos, allow_warnings)
39+ c.warn_or_error (s, pos, allow_warnings, options )
3440}
3541
3642fn (mut c Checker) warn_alloc (s string , pos token.Pos) {
@@ -43,7 +49,7 @@ fn (mut c Checker) warn_alloc(s string, pos token.Pos) {
4349 }
4450}
4551
46- fn (mut c Checker) error (message string , pos token.Pos) {
52+ fn (mut c Checker) error (message string , pos token.Pos, options MessageOptions ) {
4753 if (c.pref.translated || c.file.is_translated) && message.starts_with ('mismatched types' ) {
4854 // TODO: move this
4955 return
@@ -61,17 +67,17 @@ fn (mut c Checker) error(message string, pos token.Pos) {
6167 }
6268 msg + = ' (veb action: ${veb_action [..j ]})'
6369 }
64- c.warn_or_error (msg, pos, false )
70+ c.warn_or_error (msg, pos, false , options )
6571}
6672
67- fn (mut c Checker) fatal (message string , pos token.Pos) {
73+ fn (mut c Checker) fatal (message string , pos token.Pos, options MessageOptions ) {
6874 if (c.pref.translated || c.file.is_translated) && message.starts_with ('mismatched types' ) {
6975 // TODO: move this
7076 return
7177 }
7278 msg := message.replace ('`Array_' , '`[]' )
7379 c.pref.fatal_errors = true
74- c.warn_or_error (msg, pos, false )
80+ c.warn_or_error (msg, pos, false , options )
7581}
7682
7783fn (mut c Checker) note (message string , pos token.Pos) {
@@ -108,7 +114,7 @@ fn (mut c Checker) note(message string, pos token.Pos) {
108114 }
109115}
110116
111- fn (mut c Checker) warn_or_error (message string , pos token.Pos, warn bool ) {
117+ fn (mut c Checker) warn_or_error (message string , pos token.Pos, warn bool , options MessageOptions ) {
112118 if ! warn {
113119 $if checker_exit_on_first_error ? {
114120 eprintln ('\n\n >> checker error: ${message }, pos: ${pos }' )
@@ -148,12 +154,19 @@ fn (mut c Checker) warn_or_error(message string, pos token.Pos, warn bool) {
148154 return
149155 }
150156 if ! warn {
157+ // Use provided call_stack or fall back to file.call_stack
158+ actual_call_stack := if options.call_stack.len > 0 {
159+ options.call_stack
160+ } else {
161+ c.file.call_stack
162+ }
151163 if c.pref.fatal_errors {
152164 util.show_compiler_message ('error:' , errors.CompilerMessage{
153- pos: pos
154- file_path: file_path
155- message: message
156- details: details
165+ pos: pos
166+ file_path: file_path
167+ message: message
168+ details: details
169+ call_stack: actual_call_stack
157170 })
158171 exit (1 )
159172 }
@@ -167,11 +180,12 @@ fn (mut c Checker) warn_or_error(message string, pos token.Pos, warn bool) {
167180 if kpos ! in c.error_lines {
168181 c.error_lines[kpos] = true
169182 err := errors.Error{
170- reporter: errors.Reporter.checker
171- pos: pos
172- file_path: file_path
173- message: message
174- details: details
183+ reporter: errors.Reporter.checker
184+ pos: pos
185+ file_path: file_path
186+ message: message
187+ details: details
188+ call_stack: actual_call_stack
175189 }
176190 c.file.errors << err
177191 c.errors << err
0 commit comments