This is a special kind of switch called a type switch. You can read more
about it in the language specification where its part of the intrinsic
go syntax. https://golang.org/ref/spec#Switch_statements
Because it is a special language construct you need to look at the
compiler. You probably want to check out the default gc compiler and may
start your journey here:
https://github.com/golang/go/blob/master/src/cmd/compile/internal/gc/swt.go#L617
you can use your editor with go guru or gopls to navigate references.
Have fun!
On 28.07.20 23:39, Shane H wrote:
Hi all, I'm trying to understand what *exactly* the .(type) is doing in
the following statement
switch foo := bar.(type)
I mean, I get that foo is being assigned a type converted version of the
bar interface, but, I want to see what exactly they .(type) call does.
I have
foundĀ https://github.com/golang/go/blob/master/src/go/types/selection.go#L60
which I *think* is the method being called, but I am not sure.
So I have two questions.
1) Am I looking at the correct function
2) (and far more importantly) How do I find which method such code is
calling (it's problematic for me at this point towork out what, for
example, something defined in builtin is really calling.
Can someone point me at a resource that I have obviously overlooked?
Note: I've seen
thisĀ https://stackoverflow.com/questions/18512781/built-in-source-code-location
and, rereading it this morning it looks like "If it's not in the runtime
package, start grepping the compiler packages" - is that what I should
be doing?
--
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
<mailto:golang-nuts+unsubscr...@googlegroups.com>.
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/e52c6dbc-1cb8-44c1-a45b-be93c89bb1b7o%40googlegroups.com
<https://groups.google.com/d/msgid/golang-nuts/e52c6dbc-1cb8-44c1-a45b-be93c89bb1b7o%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/209c48b5-0078-cf1f-d5ef-ee2d95c3aa95%40mb0.org.