On Thursday, July 4, 2019 at 3:28:01 AM UTC+2, Ian Lance Taylor wrote:
>
> On Wed, Jul 3, 2019 at 6:19 PM Gert <gert....@gmail.com <javascript:>> 
> wrote: 
> > 
> > On Thursday, July 4, 2019 at 2:52:42 AM UTC+2, Ian Lance Taylor wrote: 
> >> 
> >> On Wed, Jul 3, 2019 at 4:39 PM Gert <gert....@gmail.com> wrote: 
> >> > 
> >> > On Thursday, July 4, 2019 at 12:39:34 AM UTC+2, Ian Lance Taylor 
> wrote: 
> >> >> 
> >> >> On Wed, Jul 3, 2019 at 3:30 PM Gert <gert....@gmail.com> wrote: 
> >> >> > 
> >> >> > I changed /usr/local/go/src/builtin/builtin.go 
> >> >> > 
> >> >> > type error interface { 
> >> >> >   Error() string 
> >> >> >   Unwrap() wrapper.Wrapper 
> >> >> > } 
> >> >> > 
> >> >> > But after compiling go successfully with ./all.bash it seems type 
> error is stil 
> >> >> > 
> >> >> > type error interface { 
> >> >> >   Error() string 
> >> >> > } 
> >> >> 
> >> >> The type "error" is implemented directly in the Go compiler.  The 
> code 
> >> >> in builtin/builtin.go only exists for documentation purposes.  If 
> you 
> >> >> want to change error, you'll need to change the compiler. 
> >> > 
> >> > 
> >> > Ok thx trying to dig my way in /usr/local/go/src/go but grepping for 
> error interface doesn't give me a clue where I can find the predefined 
> error interface :( do you perhaps have a path of a filename for me please 
> where it get defined? 
> >> 
> >> It's created by makeErrorInterface in 
> >> cmd/compile/internal/gc/universe.go.  But I have no idea what the 
> >> consequences of changing that function would be.  I would not be 
> >> surprised if other code in the compiler implicitly assumes the current 
> >> definition. 
> >> 
> >> Ian 
> > 
> > 
> > Thanks before I going to shoot myself in the foot let start by making a 
> new build in wrapper interface first in that file 
> > 
> > func makeWrapperInterface() *types.Type { 
> > field := types.NewField() 
> > field.Type = types.Types[TSTRING] 
> > f := functypefield(fakeRecvField(), nil, []*types.Field{field}) 
> > 
> > field = types.NewField() 
> > field.Sym = lookup("Wrapper") 
> > field.Type = f 
> > 
> > t := types.New(TINTER) 
> > t.SetInterface([]*types.Field{field}) 
> > return t 
> > } 
> > 
> > So basically this should generate a new build in 
> > 
> > type wrapper interface { 
> > Unwrap() wrapper 
> > } 
> > 
> > Because referencing to a wrapper.Wrapper pretty sure that's already out 
> of the question :) 
> > The lookup function gives me a hint that there might be some definition 
> files that describe the interface in plain text? If true do you know where 
> I can find does files specifically the error interface definition file? 
>
> As far as I know there is no definition file that defines the interface in 
> text. 
>
> As you can see by looking at the source of the lookup function, all it 
> does is look up a symbol in the local package's symbol table, and 
> create the symbol if it does not exist. 
>
> I encourage you to pursue this approach if you are interested in it, 
> but in order to do so you are going to have to learn to read and 
> understand the compiler code yourself, or find someone to work with 
> who has the time to go through it in the detail you need. 
>
> Ian 
>

Ok thanks, this my best try so far to make it happen, hopefully good enough 
to find out if it's worth it to go for a more general built-in wrapper 
interface for all types instead of a error wrapper only.

https://go-review.googlesource.com/c/go/+/184818/5 

-- 
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/a90e743b-5212-4470-a06d-80dbe42169da%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to