On Fri, Mar 13, 2026 at 10:49 PM Kurtis Rader <[email protected]> wrote:

> On Fri, Mar 13, 2026 at 10:40 PM Axel Wagner <
> [email protected]> wrote:
>
>> 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.
>>
>
> I guess I'm showing my age. But if you have to write an explicit run time
> type switch/assertion then you should assume the compile time type
> constraint might allow an unexpected type to "leak" into your function. If
> the O.P.'s example was supported by the compilation toolchain that might be
> impossible, in theory, but I would assume it's still possible if I have to
> write code to disambiguate which type I received.
>

Especially since the type constraint could be changed to allow an
unexpected type not already handled by the explicit run time type
switch/assertion code in the function I wrote.

-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
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/CABx2%3DD9GSrE0OvRxkJDcdjYvXLKnb%2BLeht2NJK3GsnhNYSXDmQ%40mail.gmail.com.

Reply via email to