Today I Learned

tags


2025/12/29

That you can use golangci-lint and a //sumtype:decl comment to declare a pale imitation of rust’s enum/pattern-matching functionality.

package main

//sumtype:decl
type MySumType interface {
        sealed()
}

type VariantA struct{}

func (*VariantA) sealed() {}

type VariantB struct{}

func (*VariantB) sealed() {}

func main() {
        switch MySumType(nil).(type) {
        case *VariantA:
        } // <-- exhaustiveness check failed for sum type 'MySumType': missing cases for VariantB
}

See https://github.com/alecthomas/go-check-sumtype see https://golangci-lint.run/docs/linters/configuration/#gochecksumtype

Since this pattern/check relies on go’s fat pointers (128 bits = 16 bytes each), it’s not good for primitive/small-sized values.