FAQ
I'd like to be able to find the source code for a given runtime named
type.

When the types are defined in global scope, this is straightforward, but
AFAICS it isn't possible in general because when two types of the same
name are defined inside two different functions in the same package,
there appears to be no way to distinguish them other than by pointer
value, which doesn't help for finding out which actual type the runtime
type is referring to.

Am I missing something?

Concretely, is there any way that I can get the info function to print
different things in this example? (without printing the pointer value
of the type)

http://play.golang.org/p/nvlt_5QD-f

   cheers,
     rog.

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Adonovan at Apr 30, 2015 at 1:11 pm

    On Thursday, 30 April 2015 05:01:08 UTC-4, rog wrote:
    I'd like to be able to find the source code for a given runtime named
    type.

    When the types are defined in global scope, this is straightforward, but
    AFAICS it isn't possible in general because when two types of the same
    name are defined inside two different functions in the same package,
    there appears to be no way to distinguish them other than by pointer
    value, which doesn't help for finding out which actual type the runtime
    type is referring to.

    Am I missing something?

    Concretely, is there any way that I can get the info function to print
    different things in this example? (without printing the pointer value
    of the type)

    http://play.golang.org/p/nvlt_5QD-f

    cheers,
    rog.

    You can rely on the identity of the type to be distinct, but not result of
    the String() method.

    If the type has any methods, you could enumerate them via
    (reflect.Type).Method and learn the source location of the method
    declaration---but of course, few local types have methods.

    The runtime type information is certainly not as rich as the information
    available to the compiler.

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.
  • Michael Hudson-Doyle at Apr 30, 2015 at 2:46 pm

    On 30 April 2015 at 21:00, roger peppe wrote:
    I'd like to be able to find the source code for a given runtime named
    type.

    When the types are defined in global scope, this is straightforward, but
    AFAICS it isn't possible in general because when two types of the same
    name are defined inside two different functions in the same package,
    there appears to be no way to distinguish them other than by pointer
    value, which doesn't help for finding out which actual type the runtime
    type is referring to.

    Am I missing something?

    Concretely, is there any way that I can get the info function to print
    different things in this example? (without printing the pointer value
    of the type)

    http://play.golang.org/p/nvlt_5QD-f
    Staring at the output of -gcflags -S certainly suggests that there
    isn't likely to be anything. It miiiiiiiiight be a reasonable
    assumption that the pointers are in the same order in the file as the
    types, but I wouldn't like to bet on it!

    Cheers,
    mwh

    --
    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+unsubscribe@googlegroups.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedApr 30, '15 at 9:01a
activeApr 30, '15 at 2:46p
posts3
users3
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase