diff --git a/gnovm/tests/files/method38.gno b/gnovm/tests/files/method38.gno new file mode 100644 index 00000000000..c5e001787aa --- /dev/null +++ b/gnovm/tests/files/method38.gno @@ -0,0 +1,22 @@ +// This test with method39.gno are answers to this issue: https://github.com/gnolang/gno/issues/4789 +package main + +import "fmt" + +type B struct{} + +func (B) Foo() string { return "Foo from B" } + +type A struct{ B } // embeds B +type T A // T retains the struct layout of A (embedding B) +type S struct{ T } // S embeds T (which embeds B) + +func main() { + var s S + fmt.Println(s.Foo()) + fmt.Println("ok") +} + +// Output: +// Foo from B +// ok diff --git a/gnovm/tests/files/method39.gno b/gnovm/tests/files/method39.gno new file mode 100644 index 00000000000..086ec43d609 --- /dev/null +++ b/gnovm/tests/files/method39.gno @@ -0,0 +1,19 @@ +// This test with method38.gno are answers to this issue: https://github.com/gnolang/gno/issues/4789 +package main + +type Base struct{} + +func (Base) Foo() {} + +type Derived Base // declared type does not inherit methods + +func main() { + var d Derived + d.Foo() // want: method not found +} + +// Error: +// main/method39.gno:12:2-7: missing field Foo in main.Derived + +// TypeCheckError: +// main/method39.gno:12:4: d.Foo undefined (type Derived has no field or method Foo)