all: make eprint[ln] behave same as print[ln] (#7595)
parent
e69e5c5b91
commit
21805ea2a5
|
@ -22,13 +22,13 @@ pub fn print(s any) {
|
|||
}
|
||||
|
||||
pub fn eprintln(s any) {
|
||||
JS.console.error(s)
|
||||
JS.console.error(s.toString())
|
||||
}
|
||||
|
||||
pub fn eprint(s any) {
|
||||
// TODO
|
||||
// $if js.node {
|
||||
JS.process.stderr.write(s)
|
||||
JS.process.stderr.write(s.toString())
|
||||
// } $else {
|
||||
// panic('Cannot `eprint` in a browser, use `eprintln` instead')
|
||||
// }
|
||||
|
|
|
@ -1589,8 +1589,8 @@ pub fn (mut c Checker) call_fn(mut call_expr ast.CallExpr) table.Type {
|
|||
unexpected_arguments_pos)
|
||||
return f.return_type
|
||||
}
|
||||
// println can print anything
|
||||
if fn_name in ['println', 'print'] && call_expr.args.len > 0 {
|
||||
// println / eprintln can print anything
|
||||
if fn_name in ['println', 'print', 'eprintln', 'eprint'] && call_expr.args.len > 0 {
|
||||
c.expected_type = table.string_type
|
||||
call_expr.args[0].typ = c.expr(call_expr.args[0].expr)
|
||||
/*
|
||||
|
|
|
@ -501,8 +501,8 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
|
|||
}
|
||||
}
|
||||
mut name := node.name
|
||||
is_print := name == 'println' || name == 'print'
|
||||
print_method := if name == 'println' { 'println' } else { 'print' }
|
||||
is_print := name in ['print', 'println', 'eprint', 'eprintln']
|
||||
print_method := name
|
||||
is_json_encode := name == 'json.encode'
|
||||
is_json_decode := name == 'json.decode'
|
||||
g.is_json_fn = is_json_encode || is_json_decode
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
fn test_print() {
|
||||
println(2.0)
|
||||
eprintln(2.0)
|
||||
}
|
||||
|
|
|
@ -10,6 +10,8 @@ fn test_autoprint_string_vargs() {
|
|||
fn add_s(column string, other_columns ...string) {
|
||||
println(column)
|
||||
println(other_columns)
|
||||
eprintln(column)
|
||||
eprintln(other_columns)
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -23,6 +25,8 @@ fn test_autoprint_int_vargs() {
|
|||
fn add_i(column int, other_columns ...int) {
|
||||
println(column)
|
||||
println(other_columns)
|
||||
eprintln(column)
|
||||
eprintln(other_columns)
|
||||
}
|
||||
|
||||
//
|
||||
|
@ -41,4 +45,6 @@ fn test_autoprint_struct_vargs() {
|
|||
fn add_point(column Point, other_columns ...Point) {
|
||||
println(column)
|
||||
println(other_columns)
|
||||
eprintln(column)
|
||||
eprintln(other_columns)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue