On Sat, 14 Mar 2026 at 06:18, Kurtis Rader <[email protected]> wrote:

> It's also unclear to me why you think using "any" would be less safe. You
> still have to use a type-assertion or type-switch to disambiguate the two
> cases. If the compiler allowed your example it might catch obvious mistakes
> at compile time but you still have to hand write code to detect at run-time
> which case is in effect. And such code should always have a "Oops! Got the
> wrong type" path.
>

In common parlance, "type-safe" means exactly, that a class of runtime
errors is prevented at compile time. That is the purpose of types.

A function constrained on `ReadStringer` would not be safer to *write*,
because, you would still need a type-switch that would need to include a
runtime panic branch. But it would be safer to *use*, because the compiler
would prevent a user from ever triggering that runtime panic.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/CAEkBMfG09J%3DUcb-TSOJa1WRiK5N5DuwdpDMWAugutZmrnYztsw%40mail.gmail.com.

Reply via email to