builtin: add panic_optional_not_set and use it in cgen for fncall()? in main

pull/9451/head weekly.2021.12.1
Delyan Angelov 2021-03-24 13:16:36 +02:00
parent 999b4a47c1
commit f8f74d8587
No known key found for this signature in database
GPG Key ID: 66886C0F12D595ED
3 changed files with 6 additions and 1 deletions

View File

@ -47,6 +47,10 @@ fn panic_debug(line_no int, file string, mod string, fn_name string, s string) {
}
}
pub fn panic_optional_not_set(s string) {
panic('optional not set ($s)')
}
// panic prints a nice error message, then exits the process with exit code of 1.
// It also shows a backtrace on most platforms.
pub fn panic(s string) {

View File

@ -5570,7 +5570,7 @@ fn (mut g Gen) or_block(var_name string, or_block ast.OrExpr, return_type table.
paline, pafile, pamod, pafn := g.panic_debug_info(or_block.pos)
g.writeln('panic_debug($paline, tos3("$pafile"), tos3("$pamod"), tos3("$pafn"), *${cvar_name}.err.msg );')
} else {
g.writeln('\tv_panic(_STR("optional not set (%.*s\\000)", 2, ${cvar_name}.err.msg));')
g.writeln('\tpanic_optional_not_set(*${cvar_name}.err.msg);')
}
} else if !isnil(g.fn_decl) && g.fn_decl.is_test {
g.gen_failing_error_propagation_for_test_fn(or_block, cvar_name)

View File

@ -137,6 +137,7 @@ pub fn mark_used(mut the_table table.Table, pref &pref.Preferences, ast_files []
if pref.is_debug {
all_fn_root_names << 'panic_debug'
}
all_fn_root_names << 'panic_optional_not_set'
if pref.is_test {
all_fn_root_names << 'main.cb_assertion_ok'
all_fn_root_names << 'main.cb_assertion_failed'