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

cmd/compile: incorrect initialization order #9094

Closed
paranoiacblack opened this issue Nov 12, 2014 · 6 comments
Closed

cmd/compile: incorrect initialization order #9094

paranoiacblack opened this issue Nov 12, 2014 · 6 comments
Milestone

Comments

@paranoiacblack
Copy link
Contributor

$ cat incorrect_init.go
package main

var (
    a = p("a") + c + b
    b = p("b") + f()
    c = p("c") + f()
    d = p("d") + 3
)

func f() int {
     d++
     return d
}

func p(s string) int {
     println(s)
     return 0
}

func main() {
    println(a, b, c, d)
}

compiling and executing produces:

$ go run incorrect_init.go
d
c
b
a
9 5 4 5

But the correct order per the spec should be: d, b, c, a, with values 9, 4, 5, 5.

See: http://tip.golang.org/ref/spec#Package_initialization
@paranoiacblack paranoiacblack self-assigned this Nov 12, 2014
@minux minux added this to the Go1.5 milestone Dec 31, 2014
@rsc rsc removed the repo-main label Apr 14, 2015
@rsc rsc modified the milestones: Go1.6, Go1.5 May 19, 2015
@rsc
Copy link
Contributor

rsc commented May 19, 2015

Is this different from #7692?

@paranoiacblack
Copy link
Contributor Author

I don't really see how they are related. This issue is about the initialization order of global variables, which, given two variables with the same number of dependencies, should initialize them in source declaration order.

@griesemer
Copy link
Contributor

@rsc @paranoiacblack They are not related. This is an actual bug. #7692 is about a feature request (Assignable is not implemented for go/types' Tuple types).

@rsc rsc changed the title cmd/gc: incorrect initialization order cmd/compile: incorrect initialization order Jun 8, 2015
@rsc
Copy link
Contributor

rsc commented Nov 4, 2015

OK, so it is different from #7692. Is it different from #7962?

@paranoiacblack
Copy link
Contributor Author

This appears to be a duplicate of #7962.

@griesemer
Copy link
Contributor

@paranoiacblack agreed.

@rsc rsc closed this as completed Dec 5, 2015
@golang golang locked and limited conversation to collaborators Dec 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants