Skip to content

Commit

Permalink
checker: add test for interface embedding and interface with erroneou…
Browse files Browse the repository at this point in the history
…s implementation (test related to #21030) (#21033)
  • Loading branch information
ttytm committed Mar 15, 2024
1 parent 3d64f9e commit 6809c67
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
@@ -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)`
@@ -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
}
}

0 comments on commit 6809c67

Please sign in to comment.