Add support for multiple interfaces

This commit is contained in:
nub31
2025-08-13 19:18:37 +02:00
parent e105676237
commit bdcf0d3e7d
2 changed files with 31 additions and 11 deletions

View File

@@ -5,28 +5,34 @@ interface Printable
func print()
}
struct Human : Printable
interface Stringable
{
func str(): cstring
}
struct Human : Printable, Stringable
{
name: cstring
func str(): cstring
{
return this^.name
}
func print()
{
puts(this^.name)
puts(this^.str())
}
}
func main(args: []cstring): i64
{
let human = alloc Human {
let human: Stringable = alloc Human {
name = "oliver"
}
human.print()
print_printable(human)
puts(human.str())
// human.print()
return 0
}
func print_printable(printable: Printable)
{
printable.print()
}