1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: allow passing any argument type to panic (#9020)

This commit is contained in:
spaceface 2021-02-28 22:57:18 +01:00 committed by GitHub
parent d63b7bc35a
commit d7252f4474
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 6 deletions

View File

@ -1896,8 +1896,8 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
unexpected_arguments_pos)
return f.return_type
}
// println / eprintln can print anything
if fn_name in ['println', 'print', 'eprintln', 'eprint'] && call_expr.args.len > 0 {
// println / eprintln / panic can print anything
if fn_name in ['println', 'print', 'eprintln', 'eprint', 'panic'] && call_expr.args.len > 0 {
c.inside_println_arg = true
c.expected_type = table.string_type
call_expr.args[0].typ = c.expr(call_expr.args[0].expr)

View File

@ -1513,7 +1513,7 @@ fn (mut g Gen) expr_with_cast(expr ast.Expr, got_type_raw table.Type, expected_t
got_sym := g.table.get_type_symbol(got_type)
// allow using the new Error struct as a string, to avoid a breaking change
// TODO: temporary to allow people to migrate their code; remove soon
if (got_type == table.error_type_idx && expected_type == table.string_type_idx) || false {
if got_type == table.error_type_idx && expected_type == table.string_type_idx {
g.expr(expr)
g.write('.msg')
return

View File

@ -734,7 +734,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
if node.name == 'error_with_code' {
name = 'error_with_code2'
}
is_print := name in ['print', 'println', 'eprint', 'eprintln']
is_print := name in ['print', 'println', 'eprint', 'eprintln', 'panic']
print_method := name
is_json_encode := name == 'json.encode'
is_json_encode_pretty := name == 'json.encode_pretty'
@ -838,9 +838,9 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
// tmps << tmp
g.write('string $tmp = ')
g.gen_expr_to_string(expr, typ)
g.writeln('; ${print_method}($tmp); string_free(&$tmp);')
g.writeln('; ${c_name(print_method)}($tmp); string_free(&$tmp);')
} else {
g.write('${print_method}(')
g.write('${c_name(print_method)}(')
g.gen_expr_to_string(expr, typ)
g.write(')')
}