When it fires. An interface literal, Repo(Find = (id) => ...), is
invalid:
Box[int](...)) nor taken from an expected type;context.Context’s Done).Minimal repro.
package main
type Clock interface {
Now() int
Zone() string
}
func main() {
val clock = Clock(Now = () => 12)
Println(clock.Now())
}
Error output.
error[GALA-E0078]: interface literal of Clock leaves out method Zone
--> main.gala:9:17
|
9 | val clock = Clock(Now = () => 12)
| ^^^^^ give every method of Clock, as in `Zone = ...`
|
= hint: give every method of Clock, as in `Zone = ...`
Fix. Give every method, each by its name:
package main
type Clock interface {
Now() int
Zone() string
}
func main() {
val clock = Clock(Now = () => 12, Zone = () => "UTC")
Println(clock.Now(), clock.Zone())
}
For an interface a literal cannot build, declare a struct that implements it.
Rationale. A literal is a complete implementation of the interface: the compiler checks that it gives every method, so a value of the interface never has a method that does nothing. Naming each method keeps a literal readable and independent of the order the interface declares its methods in. See Interface Literals.