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) {
|
pub fn eprintln(s any) {
|
||||||
JS.console.error(s)
|
JS.console.error(s.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn eprint(s any) {
|
pub fn eprint(s any) {
|
||||||
// TODO
|
// TODO
|
||||||
// $if js.node {
|
// $if js.node {
|
||||||
JS.process.stderr.write(s)
|
JS.process.stderr.write(s.toString())
|
||||||
// } $else {
|
// } $else {
|
||||||
// panic('Cannot `eprint` in a browser, use `eprintln` instead')
|
// 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)
|
unexpected_arguments_pos)
|
||||||
return f.return_type
|
return f.return_type
|
||||||
}
|
}
|
||||||
// println can print anything
|
// println / eprintln can print anything
|
||||||
if fn_name in ['println', 'print'] && call_expr.args.len > 0 {
|
if fn_name in ['println', 'print', 'eprintln', 'eprint'] && call_expr.args.len > 0 {
|
||||||
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)
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -501,8 +501,8 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mut name := node.name
|
mut name := node.name
|
||||||
is_print := name == 'println' || name == 'print'
|
is_print := name in ['print', 'println', 'eprint', 'eprintln']
|
||||||
print_method := if name == 'println' { 'println' } else { 'print' }
|
print_method := name
|
||||||
is_json_encode := name == 'json.encode'
|
is_json_encode := name == 'json.encode'
|
||||||
is_json_decode := name == 'json.decode'
|
is_json_decode := name == 'json.decode'
|
||||||
g.is_json_fn = is_json_encode || is_json_decode
|
g.is_json_fn = is_json_encode || is_json_decode
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
fn test_print() {
|
fn test_print() {
|
||||||
println(2.0)
|
println(2.0)
|
||||||
|
eprintln(2.0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ fn test_autoprint_string_vargs() {
|
||||||
fn add_s(column string, other_columns ...string) {
|
fn add_s(column string, other_columns ...string) {
|
||||||
println(column)
|
println(column)
|
||||||
println(other_columns)
|
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) {
|
fn add_i(column int, other_columns ...int) {
|
||||||
println(column)
|
println(column)
|
||||||
println(other_columns)
|
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) {
|
fn add_point(column Point, other_columns ...Point) {
|
||||||
println(column)
|
println(column)
|
||||||
println(other_columns)
|
println(other_columns)
|
||||||
|
eprintln(column)
|
||||||
|
eprintln(other_columns)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue