@@ -373,6 +373,34 @@ fn test_veb_implicit_ctx_alias_uses_user_context_name() {
373373 assert normalized.contains ('veb__Result main__App_index(main__App app, main__Context* c) { main__App_log(app, *c); GC_reachable_here(&c); return main__App_nested(app, c); }' )
374374}
375375
376+ fn test_veb_implicit_ctx_alias_on_context_receiver_tmpl_not_found () {
377+ os.chdir (vroot) or {}
378+ test_dir := os.join_path (os.vtmp_dir (), 'coutput_veb_context_receiver_tmpl_not_found' )
379+ os.rmdir_all (test_dir) or {}
380+ os.mkdir_all (os.join_path (test_dir, 'web' ))!
381+ test_source := os.join_path (test_dir, 'main.v' )
382+ os.write_file (os.join_path (test_dir, 'web' , 'notfound.html' ), '<h1>@ctx.req.url</h1>\n ' )!
383+ os.write_file (test_source,
384+ ['module main' , '' , 'import veb' , '' , 'pub struct Context {' , '\t veb.Context' , '}' , '' , 'pub struct App {}' , '' , 'pub fn (mut c Context) not_found() veb.Result {' , '\t c.res.set_status(.not_found)' , "\t return c.html(\$ tmpl('web/notfound.html'))" , '}' , '' , 'fn main() {' , '\t mut app := App{}' , '\t veb.run[App, Context](mut app, 8080)' , '}' ].join ('\n ' ) +
385+ '\n ' )!
386+ defer {
387+ os.rmdir_all (test_dir) or {}
388+ }
389+ test_exe := os.join_path (test_dir, 'app' )
390+ compile_cmd := '${os .quoted_path (vexe )} -gc boehm_full_opt -o ${os .quoted_path (test_exe )} ${os .quoted_path (test_source )}'
391+ ensure_compilation_succeeded (os.execute (compile_cmd), compile_cmd)
392+ c_cmd := '${os .quoted_path (vexe )} -gc boehm_full_opt -o - ${os .quoted_path (test_source )}'
393+ compilation := os.execute (c_cmd)
394+ ensure_compilation_succeeded (compilation, c_cmd)
395+ not_found_start := 'veb__Result main__Context_not_found(main__Context* c) {'
396+ assert compilation.output.contains (not_found_start)
397+ not_found_body :=
398+ compilation.output.all_after (not_found_start).all_before ('VV_LOC void main__main' )
399+ assert ! not_found_body.contains ('GC_reachable_here(&ctx);' )
400+ assert not_found_body.contains ('GC_reachable_here(&c);' )
401+ assert not_found_body.contains ('return veb__Context_html(&c->Context, _tmpl_res_' )
402+ }
403+
376404fn does_line_match_one_of_generated_lines (line string , generated_c_lines []string ) bool {
377405 for cline in generated_c_lines {
378406 if line == cline {
0 commit comments