[go-nuts] Re: Idea extending xerror.As

2021-09-23 Thread Haddock
Brian Candler schrieb am Sonntag, 19. September 2021 um 20:46:45 UTC+2: > > I'm not sure how useful that is though, especially because "return" inside > that anonymous function will return from that anonymous function, not the > outer function. > https://go2goplay.golang.org/p/h6ZRnqM5cRx >

[go-nuts] Re: Idea extending xerror.As

2021-09-19 Thread Brian Candler
https://go2goplay.golang.org/p/S_RDDxhTI1a In fact, it can infer the type parameter: https://go2goplay.golang.org/p/rk7jyt3ob0v I'm not sure how useful that is though, especially because "return" inside that anonymous function will return from that anonymous function, not the outer function.

[go-nuts] Re: Idea extending xerror.As

2021-09-19 Thread Haddock
Brian Candler schrieb am Sonntag, 19. September 2021 um 13:38:49 UTC+2: > Also, I may be missing the point, but does the following do what you want? > https://play.golang.org/p/86DQD5QMbJ3 > > _, err := os.Open("non-existing") > if pe := ({}); errors.As(err, ) { > fmt.Println("Failed at path:",

[go-nuts] Re: Idea extending xerror.As

2021-09-19 Thread Brian Candler
Also, I may be missing the point, but does the following do what you want? https://play.golang.org/p/86DQD5QMbJ3 _, err := os.Open("non-existing") if pe := ({}); errors.As(err, ) { fmt.Println("Failed at path:", pe.Path) } On Sunday, 19 September 2021 at 12:24:13 UTC+1 Brian Candler wrote: > I

[go-nuts] Re: Idea extending xerror.As

2021-09-19 Thread Brian Candler
I notice at least three things from your proposed syntax: 1. Passing a *type* as an argument ("os.PathError"), rather than a *value of a type* 2. A control structure. This might involve passing a block of code as a hidden argument (like blocks in Ruby), or some sort of macro expansion. 3. The