checker: add test for interface embedding and interface with erroneous implementation (test related to #21030) (#21033)

This commit is contained in:
Turiiya 2024-03-15 16:11:38 +01:00 committed by GitHub
parent 3d64f9e465
commit 6809c67805
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,9 @@
vlib/v/checker/tests/struct_init_with_iface_embed_iface_with_incorrect_method_impl_ref_field_err.vv:21:3: error: `&Stream` incorrectly implements method `read` of interface `Refresher`: expected return type `!int`
19 | s := &Stream{}
20 | _ := &Server{
21 | refresher: s
| ~~~~~~~~~~~~
22 | }
23 | }
Details: main.Refresher has `fn read(x main.Refresher, buf []u8) !int`
main.Stream has `fn read(a main.Stream, buf []u8)`

View File

@ -0,0 +1,23 @@
interface Refresher {
Reader
}
interface Reader {
read(buf []u8) !int
}
struct Server {
refresher Refresher
}
struct Stream {}
// Implementation is missing the return type.
fn (a Stream) read(buf []u8) {}
fn test_struct_init_with_interface_field() {
s := &Stream{}
_ := &Server{
refresher: s
}
}