checker: fix passing enum to a method expecting string
parent
228486555c
commit
9c028bb299
|
@ -333,7 +333,7 @@ fn verror(s string) {
|
||||||
util.verror('builder error', s)
|
util.verror('builder error', s)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (mut b Builder) timing_message(msg string, ms int) {
|
pub fn (mut b Builder) timing_message(msg string, ms i64) {
|
||||||
formatted_message := '$msg: ${util.bold(ms.str())} ms'
|
formatted_message := '$msg: ${util.bold(ms.str())} ms'
|
||||||
if b.pref.show_timings {
|
if b.pref.show_timings {
|
||||||
println(formatted_message)
|
println(formatted_message)
|
||||||
|
|
|
@ -963,7 +963,9 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
|
||||||
// }
|
// }
|
||||||
// same ancestor? let it be
|
// same ancestor? let it be
|
||||||
if exp_arg_sym.parent_idx == got_arg_sym.parent_idx {
|
if exp_arg_sym.parent_idx == got_arg_sym.parent_idx {
|
||||||
continue
|
if got_arg_sym.parent_idx != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if got_arg_typ != table.void_type {
|
if got_arg_typ != table.void_type {
|
||||||
c.error('cannot use type `$got_arg_sym.str()` as type `$exp_arg_sym.str()` in argument ${i+1} to `${left_type_sym.name}.$method_name`',
|
c.error('cannot use type `$got_arg_sym.str()` as type `$exp_arg_sym.str()` in argument ${i+1} to `${left_type_sym.name}.$method_name`',
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
vlib/v/checker/tests/method_wrong_arg_type.v:8:4: error: cannot use type `MyEnum` as type `string` in argument 1 to `Sss.info`
|
||||||
|
6 | e := MyEnum.x
|
||||||
|
7 | s := Sss{}
|
||||||
|
8 | s.info(e)
|
||||||
|
| ~~~~~~~
|
||||||
|
9 | }
|
|
@ -0,0 +1,9 @@
|
||||||
|
enum MyEnum { x y z }
|
||||||
|
pub fn (e MyEnum) str() string { return int(e).str() }
|
||||||
|
struct Sss { }
|
||||||
|
fn (s Sss) info(msg string) { println(msg) }
|
||||||
|
fn main() {
|
||||||
|
e := MyEnum.x
|
||||||
|
s := Sss{}
|
||||||
|
s.info(e)
|
||||||
|
}
|
Loading…
Reference in New Issue