As Brian alludes to, note that Go lets you redefine many (maybe all?) identifiers that are defined in the "universe" block: https://go.dev/play/p/qbF94AG-VbA
Code review is a wonderful tool to avoid people from doing silly things like that in a codebase! On Thursday, December 16, 2021 at 3:08:10 AM UTC-7 amenz...@gmail.com wrote: > Ah, that makes sense, thanks. > > Perhaps it would be better to require the type-parameter names in method > declarations to have the same names as in the type declaration. > I think this is something that linters should do one day. > > On Thursday, December 16, 2021 at 12:39:44 PM UTC+3 > axel.wa...@googlemail.com wrote: > >> It doesn't do "complete nonsense". It's equivalent to writing `func (r >> Result[T])`, it just uses a different identifier for the type-parameter. >> I agree that this looks confusing, which is why you shouldn't do it. >> Perhaps it would be better to require the type-parameter names in method >> declarations to have the same names as in the type declaration. But note >> that even that wouldn't prevent you from doing >> >> type Result[bool any] struct {} >> >> func (r Result[bool]) Method() { /* … */ } >> >> which still looks exactly as confusing. >> >> On Thu, Dec 16, 2021 at 10:24 AM Aliaksandr Mianzhynski < >> amenz...@gmail.com> wrote: >> >>> I'm a bit confused about ability to change struct constraints in methods >>> that it looks like a method definition for a specific type, but in reality >>> it does complete nonsense: >>> >>> Here's an example: https://gotipplay.golang.org/p/zFLJMdp5mbO >>> >>> -- >>> 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...@googlegroups.com. >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/golang-nuts/ad9317b8-aa69-4077-b24d-f6639eaf55e7n%40googlegroups.com >>> >>> <https://groups.google.com/d/msgid/golang-nuts/ad9317b8-aa69-4077-b24d-f6639eaf55e7n%40googlegroups.com?utm_medium=email&utm_source=footer> >>> . >>> >> -- 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/db6a0786-296d-4bac-85a2-95a0a66767a9n%40googlegroups.com.