In that case, the 'T' is whatever the type argument is to the generic "run" 
function.  So as long as "run" can infer its argument type, then you're all 
good.

That's the "easy" case for type inference: an argument of type T.

    func run[T any](t T)

You call run with a string literal, so clearly it's run[string]("howdy")

OTOH, your "interfaceFunc" has a more complex signature:

    func interfaceFunc[T any](x GenericInterface[T])

On Monday, 20 June 2022 at 14:26:40 UTC+1 Mike Andrews wrote:

> here's an example more like my specific use case that i just mentioned, 
> with the surprising inference behavior --- 
> https://go.dev/play/p/BNmjlYejawZ
>
> On Monday, June 20, 2022 at 9:21:34 AM UTC-4 Mike Andrews wrote:
>
>> great, thanks brian, works like a charm. surprisingly, even works in my 
>> specific use case calling it like "interfaceFunc[T](x)" generically without 
>> being specific like "[string]", wondering why the compiler's inference is 
>> like that? is it a flaw or just a limitation of the concept per se?
>>
>> On Monday, June 20, 2022 at 8:44:06 AM UTC-4 Brian Candler wrote:
>>
>>> Type inference doesn't work in all cases.  When required, just be 
>>> explicit:
>>>
>>>         interfaceFunc[string](x)
>>>
>>> https://go.dev/play/p/j66sXsfMUBl
>>>
>>> On Monday, 20 June 2022 at 13:06:57 UTC+1 Mike Andrews wrote:
>>>
>>>> anyone know why this simple case doesn't compile? i'm trying to call a 
>>>> function defined for generic interface type, which fails to compile for 
>>>> struct instance: https://go.dev/play/p/Y3Gdr2ILpK4
>>>>
>>>>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/627ce064-6593-4f61-8379-32ee9208a0d0n%40googlegroups.com.

Reply via email to