|
|
|
|
|
by 9rx
500 days ago
|
|
Okay, sure. Here is an explicit code example: func foo(bar func() error) bool {
err := bar()
if err != nil {
return true
}
return false
}
func TestFooReturnsTrueWhenBarReturnsError(t *testing.T) {
if foo(func() error { return nil }) {
t.Error("expected foo to return false")
}
if !foo(func() error { return errors.New("error") }) {
t.Error("expected foo to return true")
}
}
Now it is your turn. Modify the body of function foo to remove the error check as you imagine it would be if it were forgotten.This https://go.dev/play/p/k8zDQj5knaj is what I envision you are talking about, but clearly that cannot be it. As you can see it loudly proclaims that I "forgot", making this forgetfulness idea you have come up with impossible. So, what it is that you actually have in mind? |
|
Provide an example backing up your claim regarding pattern matching + union types:
> Like in the same way you might forget to write pattern matching code?