Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/tools/cmd/eg: embedded fields are mishandled #10252

Open
josharian opened this issue Mar 25, 2015 · 3 comments

Comments

Projects
None yet
5 participants
@josharian
Copy link
Contributor

commented Mar 25, 2015

$GOPATH/src/egbug/x.go:

package egbug

type T struct {
    *E
    E2 *E
}

type E struct {
    Next *T
}

func main() {
    var t *T
    t.Next = new(T)
}

Template:

package p

import "egbug"

func before(t *egbug.T) *egbug.T { return t.Next }
func after(t *egbug.T) *egbug.T  { return t.E2.Next }

eg output:

package egbug

type T struct {
    *E
    E2  *E
}

type E struct {
    Next *T
}

func main() {
    var t *T
    t.E2.E2.Next = new(T)
}

The second statement in main should be t.E2.Next, not t.E2.E2.Next. The output does not compile.

@josharian

This comment has been minimized.

Copy link
Contributor Author

commented Mar 25, 2015

This is not just theoretical. I encountered it while working on a follow-up to CL 7360. Note that because the output doesn't typecheck, I can't just use eg to fix it as a workaround.

@josharian

This comment has been minimized.

Copy link
Contributor Author

commented Mar 25, 2015

...and actually, it looks like this has to do with applying the transformation too many times, not with embedded fields. Sorry. Still a bug, though. :)

@mikioh mikioh added the repo-tools label Mar 26, 2015

@rsc rsc added this to the Unplanned milestone Apr 10, 2015

@rsc rsc changed the title cmd/eg: embedded fields are mishandled x/tools/cmd/eg: embedded fields are mishandled Apr 14, 2015

@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015

@rsc rsc removed the repo-tools label Apr 14, 2015

@Ripounet

This comment has been minimized.

Copy link

commented Jul 19, 2015

I noticed the same problem each time the "after" matches the "before" pattern, e.g. :

func before(str string) string { return strings.ToLower(str) }
func after(str string) string  { return strings.ToLower("[" + str + "]") }

-> brackets added twice instead of once.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.