4 ms·
Sure, with = (in this case the shorthand :=), what happens before can change how it works. The second := in case 2 should have raised a visual alarm. The fact
by pishpash 6y ago
Sure, with = (in this case the shorthand :=), what happens before can change how it works.
The second := in case 2 should have raised a visual alarm. The fact that := even assigned for err a second time means inference could have happened, like
err = (*MyErr)(nil)
To catch this, you could have written the nil check like:
fmt.Printf("err is nil: %v\n", (*MyErr)(err) == nil)
and the compiler will croak. Or, to prevent this, replicate the inference explicitly:
fmt.Printf("err is nil: %v\n", err == (*MyErr)(nil))