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

go/printer: build constraints are moved above block comments #66033

Open
zyxkad opened this issue Feb 29, 2024 · 5 comments
Open

go/printer: build constraints are moved above block comments #66033

zyxkad opened this issue Feb 29, 2024 · 5 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@zyxkad
Copy link

zyxkad commented Feb 29, 2024

Go version

go version go1.22.0 darwin/arm64

Output of go env in your module/workspace:

Not relative

What did you do?

  1. https://go.dev/play/p/XfUekq-wb8i
  2. Click the format button or run go fmt
/* Ok, the LICENSE is...
 * UNLICENSED
 */

// some test comments here

//go:build !ignore

// some package description
package main

What did you see happen?

//go:build !ignore

/* Ok, the LICENSE is...
 * UNLICENSED
 */

// some test comments here

// some package description
package main

What did you expect to see?

Nothing should happen, so

/* Ok, the LICENSE is...
 * UNLICENSED
 */

// some test comments here

//go:build !ignore

// some package description
package main
@zyxkad
Copy link
Author

zyxkad commented Feb 29, 2024

I am putting my license header in the block comment, so I wish it will stay at the top and not be moved

@zyxkad
Copy link
Author

zyxkad commented Feb 29, 2024

Another example:

// aaa
/* bbb */

//go:build ignore

will become

//go:build ignore

// aaa
/* bbb */

Really weird

@seankhliao seankhliao changed the title cmd/gofmt: Format the file that has build flag will cause all the blocky comment above the flag move down go/printer: build constraints are moved above block comments Feb 29, 2024
@seankhliao
Copy link
Member

the old build constraint format // +build could only be preceded by line comments and not block comments so they were moved up

https://github.com/golang/go/blob/master/src/go/printer/gobuild.go#L13

@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Feb 29, 2024
@adonovan
Copy link
Member

adonovan commented Mar 4, 2024

What is the "ohh" comment if not the copyright header?

@zyxkad
Copy link
Author

zyxkad commented Mar 4, 2024

the ohh just some test comments 💦

I edited the example so it will makes more sense

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants