1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

checker: fix passing enum to a method expecting string

This commit is contained in:
Delyan Angelov 2020-07-28 13:50:40 +03:00
parent 228486555c
commit 9c028bb299
4 changed files with 19 additions and 2 deletions

View File

@ -333,7 +333,7 @@ fn verror(s string) {
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'
if b.pref.show_timings {
println(formatted_message)

View File

@ -963,7 +963,9 @@ pub fn (mut c Checker) call_method(mut call_expr ast.CallExpr) table.Type {
// }
// same ancestor? let it be
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 {
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`',

View File

@ -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 | }

View File

@ -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)
}