mirror of
https://github.com/vlang/v.git
synced 2025-09-13 01:16:02 -04:00
This commit is contained in:
parent
c91cb87671
commit
7dc3889f19
@ -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.option_or_result = true
|
||||||
}
|
}
|
||||||
c.table.used_features.print_types[node.args[0].typ.idx()] = 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() {
|
if node.args[0].typ.is_ptr() {
|
||||||
c.table.used_features.auto_str_ptr = true
|
c.table.used_features.auto_str_ptr = true
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
&xxx 1:1:1
|
@ -0,0 +1 @@
|
|||||||
|
&xxx 1:1:1
|
42
vlib/v/tests/skip_unused/print_interface_smartcast.vv
Normal file
42
vlib/v/tests/skip_unused/print_interface_smartcast.vv
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user