markused: fix printing smartcasted interface values (fix #24579) (#24583)

This commit is contained in:
Felipe Pena 2025-05-29 05:09:17 -03:00 committed by GitHub
parent c91cb87671
commit 7dc3889f19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 54 additions and 0 deletions

View File

@ -138,6 +138,16 @@ fn (mut c Checker) markused_fn_call(mut node ast.CallExpr) {
c.table.used_features.option_or_result = true
}
c.table.used_features.print_types[node.args[0].typ.idx()] = true
if !c.table.used_features.auto_str_ptr && node.args[0].expr is ast.Ident {
var_obj := node.args[0].expr.obj
if var_obj is ast.Var {
if var_obj.orig_type != 0
&& c.table.final_sym(var_obj.orig_type).kind == .interface {
c.table.used_features.auto_str_ptr = true
return
}
}
}
}
if node.args[0].typ.is_ptr() {
c.table.used_features.auto_str_ptr = true

View File

@ -0,0 +1 @@
&xxx 1:1:1

View File

@ -0,0 +1 @@
&xxx 1:1:1

View File

@ -0,0 +1,42 @@
module main
pub struct MyError implements IError {
pub:
msg string
code int
domain int
level int
}
pub fn (e MyError) str() string {
return '${e.msg} ${e.code}:${e.domain}:${e.level}'
}
pub fn (e MyError) msg() string {
return e.msg
}
pub fn (e MyError) code() int {
return e.code
}
fn MyError.new(msg string, code int, domain int, level int) MyError {
return MyError{
msg: msg
code: code
domain: domain
level: level
}
}
fn foo() ! {
return MyError.new('xxx', 1, 1, 1)
}
fn main() {
foo() or {
if err is MyError {
eprintln(err)
}
}
}