File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2143,7 +2143,9 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
21432143 }
21442144 }
21452145 if ! print_auto_str {
2146- if is_print {
2146+ if is_print && node.args[0 ].expr ! is ast.CallExpr {
2147+ // only need for `println(err)`
2148+ // not need for `println(err.msg())`
21472149 g.inside_interface_deref = true
21482150 defer (fn ) {
21492151 g.inside_interface_deref = false
Original file line number Diff line number Diff line change 1+ struct MyError {
2+ code int
3+ state string
4+ }
5+
6+ pub fn (e MyError) msg () string {
7+ return 'something went wrong'
8+ }
9+
10+ pub fn (e MyError) code () int {
11+ return e.code
12+ }
13+
14+ fn foo () ! {
15+ return MyError{}
16+ }
17+
18+ fn test_interface_err_msg_print () {
19+ foo () or {
20+ if err is MyError {
21+ eprintln (err.msg ())
22+ exit (err.code ())
23+ } else {
24+ panic (err)
25+ }
26+ }
27+ }
You can’t perform that action at this time.
0 commit comments