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
Open

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

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

Comments

@josharian
Copy link
Contributor

$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
Copy link
Contributor Author

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
Copy link
Contributor Author

...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. :)

@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
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants