v
v copied to clipboard
checker: check error of casting to interface (fix #17522)
This PR check error of casting to interface (fix #17522).
- Check error of casting to interface.
- Add test.
fn main() {
dump(foo()!)
}
fn foo() !int {
// do something
if true {
return 1
}
return my_error()
}
struct CustomError {
pub:
msg string
code int
}
fn my_error() IError {
return IError(CustomError{})
}
PS D:\Test\v\tt1> v run .
tt1.v:20:9: notice: `CustomError` doesn't implement method `msg` of interface `IError`. The usage of fields is being deprecated in favor of methods.
18 |
19 | fn my_error() IError {
20 | return IError(CustomError{})
| ~~~~~~~~~~~~~~~~~~~~~
21 | }
tt1.v:20:9: error: `CustomError` does not implement interface `IError`, cannot cast `CustomError` to interface `IError`
18 |
19 | fn my_error() IError {
20 | return IError(CustomError{})
| ~~~~~~~~~~~~~~~~~~~~~
21 | }