On Mon, Mar 2, 2020 at 2:05 PM Warren Stephens <wsteph...@prognoshealth.com> wrote:
> What if local var pointers (like x above) were invalid to list in a *with* > statement? > > Would there then be any other breaking examples? Can it be broken using > passed pointers or heap pointers? > Of course. In fact, that was my thought process behind that code. It's obviously nonsensical as it is, to just compare pointers like that. But that comparison was supposed to signify exactly that situation, that you pass `x` and `y` to different functions, which then might or might not retain them (and might or might not break if they point to the same location or not). You don't even have to pass them. Consider var x *int func F() { a, e := F() x = &e step with: a b, e := F() fmt.Println(x == y) _, _ = a, b // to "use" these } You also get the problem of "what's a pointer". Like, to actually help, slices, maps, channels and interfaces all would have to count as "pointers" too. Even structs would have to, if they *contained* any pointers. Pretty soon, you get to the point where you usually can't use `with`, because you'd have to use at least one of these restricted types. I would be willing to be surprised - but I really don't believe this can be made to work. I can't *prove* it, but ISTM that in any case, you'd have to end up compiling it into separate functions anyway - and have it behave exactly the same way. At which point, the whole argument of avoiding the cost of function calls, or that refactoring is dangerous and might introduce breakage, just disappears - because it behaves exactly the same as separating things into functions anyway. > > Warren > > -- > 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/503e963a-49a0-4d35-8555-96fdb0ee7a53%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/503e963a-49a0-4d35-8555-96fdb0ee7a53%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/CAEkBMfHiT%2BQ0C%3D%3DasxRDFazbR47esNjoJESN3Uo8qde4BNmoVA%40mail.gmail.com.