-
Couldn't load subscription status.
- Fork 14
Open
Description
sealed interfaces include a no-op private method so that only package-local types can implement the interface. it is therefore possible to check exhaustiveness statically.
example:
type Payload interface {
sealed()
}
type FooPayload struct {
Foo string
}
func (p FooPayload) sealed() {}
type BarPayload struct {
Bar int
}
func (p BarPayload) sealed() {}
// . . .
switch p := somePayload.(type) {
case FooPayload:
fmt.Println(p.Foo)
case BarPayload:
fmt.Printf("%d", p.Bar)
}see https://github.com/alecthomas/go-check-sumtype , which works but does not use analysis, and thus cannot be used with tools like nogo
Metadata
Metadata
Assignees
Labels
No labels