Skip to content

import init: now import init sort is a-z, but old is use import order #63500

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

Closed
deatil opened this issue Oct 11, 2023 · 3 comments
Closed

import init: now import init sort is a-z, but old is use import order #63500

deatil opened this issue Oct 11, 2023 · 3 comments

Comments

@deatil
Copy link

deatil commented Oct 11, 2023

What version of Go are you using (go version)?

$ go version

go1.21

Does this issue reproduce with the latest release?

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

What did you do?

init run e:

import (
    _ "gotest/a"
    _ "gotest/c"
    _ "gotest/bb/a"
    _ "gotest/b"
)

now show:

a
b
bb-a
c

old show:

a
c
bb-a
b

this is a bug.

What did you expect to see?

What did you see instead?

@mateusz834
Copy link
Member

This may change the behavior of some programs that rely on a specific initialization ordering that was not expressed by explicit imports. The behavior of such programs was not well defined by the spec in past releases. The new rule provides an unambiguous definition.

https://go.dev/doc/go1.21#language

@deatil
Copy link
Author

deatil commented Oct 11, 2023

This may change the behavior of some programs that rely on a specific initialization ordering that was not expressed by explicit imports. The behavior of such programs was not well defined by the spec in past releases. The new rule provides an unambiguous definition.

https://go.dev/doc/go1.21#language

so, go will use the sort type for init? that, some used init for sort will change use type.

@seankhliao
Copy link
Member

this is working as intended and documented, see #57411

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2023
@golang golang locked and limited conversation to collaborators Oct 10, 2024
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

4 participants