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/gofmt: call("arg", newline /* comment */) is changed to syntax error #27574

Open
rillig opened this issue Sep 9, 2018 · 5 comments
Open

cmd/gofmt: call("arg", newline /* comment */) is changed to syntax error #27574

rillig opened this issue Sep 9, 2018 · 5 comments
Assignees
Labels
Milestone

Comments

@rillig
Copy link
Contributor

@rillig rillig commented Sep 9, 2018

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

go version go1.10.3 windows/amd64

Does this issue reproduce with the latest release?

Yes, see https://play.golang.org/p/Gv-AmNeMSdT

What did you do?

Open https://play.golang.org/p/Gv-AmNeMSdT, click Format.

What did you expect to see?

After formatting, the program still compiles.

What did you see instead?

Gofmt removes the comma, leading to a syntax error:

prog.go:8:33: syntax error: unexpected newline, expecting comma or )

@dominikh
Copy link
Member

@dominikh dominikh commented Sep 9, 2018

@agnivade
Copy link
Contributor

@agnivade agnivade commented Sep 9, 2018

Seems like a valid bug to me. Any reason this needs to be 'NeedsDecision' ?

@agnivade agnivade added this to the Go1.12 milestone Sep 9, 2018
@dominikh
Copy link
Member

@dominikh dominikh commented Sep 9, 2018

@agnivade No reason other than me misunderstanding the labels, it seems.

@dominikh dominikh added NeedsFix and removed NeedsDecision labels Sep 9, 2018
@rillig
Copy link
Contributor Author

@rillig rillig commented Sep 9, 2018

The related code is in package go/printer:

  • printer.exprList checks whether the arguments are on a single line (line == endLine).
  • If the arguments span multiple lines, the comma is inserted correctly.
  • If the code for the single-line case is deleted, the comma is inserted correctly, but the comment is not indented properly.

Test cases:

package main

func issue27574a() {
	print("",
		/**/)
}

func issue27574b() {
	print(`
	`,
		/**/)
}

func issue27574c() {
	print(
		"",
		/**/)
}

func issue27574d() {
	print(
		"",
		/**/)
}

func issue27574e() {
	print("", "",
		/**/)
}
@griesemer griesemer self-assigned this Sep 10, 2018
@griesemer
Copy link
Contributor

@griesemer griesemer commented Dec 5, 2018

Too late for 1.12

@griesemer griesemer modified the milestones: Go1.12, Go1.13 Dec 5, 2018
@griesemer griesemer modified the milestones: Go1.13, Go1.14 May 7, 2019
@rsc rsc modified the milestones: Go1.14, Backlog Oct 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.