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:
parent
d63b7bc35a
commit
d7252f4474
@ -1896,8 +1896,8 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
|
|||||||
unexpected_arguments_pos)
|
unexpected_arguments_pos)
|
||||||
return f.return_type
|
return f.return_type
|
||||||
}
|
}
|
||||||
// println / eprintln can print anything
|
// println / eprintln / panic can print anything
|
||||||
if fn_name in ['println', 'print', 'eprintln', 'eprint'] && call_expr.args.len > 0 {
|
if fn_name in ['println', 'print', 'eprintln', 'eprint', 'panic'] && call_expr.args.len > 0 {
|
||||||
c.inside_println_arg = true
|
c.inside_println_arg = true
|
||||||
c.expected_type = table.string_type
|
c.expected_type = table.string_type
|
||||||
call_expr.args[0].typ = c.expr(call_expr.args[0].expr)
|
call_expr.args[0].typ = c.expr(call_expr.args[0].expr)
|
||||||
|
@ -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)
|
got_sym := g.table.get_type_symbol(got_type)
|
||||||
// allow using the new Error struct as a string, to avoid a breaking change
|
// 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
|
// 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.expr(expr)
|
||||||
g.write('.msg')
|
g.write('.msg')
|
||||||
return
|
return
|
||||||
|
@ -734,7 +734,7 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
|
|||||||
if node.name == 'error_with_code' {
|
if node.name == 'error_with_code' {
|
||||||
name = 'error_with_code2'
|
name = 'error_with_code2'
|
||||||
}
|
}
|
||||||
is_print := name in ['print', 'println', 'eprint', 'eprintln']
|
is_print := name in ['print', 'println', 'eprint', 'eprintln', 'panic']
|
||||||
print_method := name
|
print_method := name
|
||||||
is_json_encode := name == 'json.encode'
|
is_json_encode := name == 'json.encode'
|
||||||
is_json_encode_pretty := name == 'json.encode_pretty'
|
is_json_encode_pretty := name == 'json.encode_pretty'
|
||||||
@ -838,9 +838,9 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
|
|||||||
// tmps << tmp
|
// tmps << tmp
|
||||||
g.write('string $tmp = ')
|
g.write('string $tmp = ')
|
||||||
g.gen_expr_to_string(expr, typ)
|
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 {
|
} else {
|
||||||
g.write('${print_method}(')
|
g.write('${c_name(print_method)}(')
|
||||||
g.gen_expr_to_string(expr, typ)
|
g.gen_expr_to_string(expr, typ)
|
||||||
g.write(')')
|
g.write(')')
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user