2 ms·
> If you want sum types, a better approach is to combine the sort of code [...] I'm currently of the opinion that where you truly need this type of thing, wri
by 9rx 10mo ago
> If you want sum types, a better approach is to combine the sort of code [...]
I'm currently of the opinion that where you truly need this type of thing, write tests that use the ast package to validate that your expectations hold. That way you don't need to do anything strange with the code, and logic failure will show up alongside all of your other logic failures.
While it does venture into implementation details that shouldn't be tested, Go offers a discriminator between your actual tests and throwaway tests (i.e. `package foo_test` v.s. `package foo`), so as long as you've clearly mark the intent I find this to be an acceptable tradeoff. As implementation changes, and you no longer need that validation, others will know that your throwaway tests are intended as such.