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/format: Source mishandles parens on malformed input #29593

Closed
josharian opened this issue Jan 7, 2019 · 2 comments
Closed

go/format: Source mishandles parens on malformed input #29593

josharian opened this issue Jan 7, 2019 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@josharian
Copy link
Contributor

josharian commented Jan 7, 2019

Found by go-fuzz, unlikely to occur in real code. Very low priority.

func main() {
	in := []byte("g(func()())")
	out, err := format.Source(in)
	if err != nil {
		panic(err)
	}
	fmt.Printf("in : %q\nout: %q\n", in, out)
	return
}

Result:

in : "g(func()())"
out: "g(func())"

Observe the dropped parens pair.

If input is "g(func()()())" instead (extra parens pair), the result instead has misplaced parens:

in : "g(func()()())"
out: "g((func())())"
@josharian josharian added this to the Unplanned milestone Jan 7, 2019
@josharian josharian added the NeedsFix The path to resolution is known, but the work has not been done. label Jan 7, 2019
@bcmills
Copy link
Contributor

bcmills commented Jan 9, 2019

Compare https://play.golang.org/p/jmef0XQwDn3.

The error in the example source is that the function passed to g is missing its FunctionBody, but other than that it seems that go/format is correctly parsing func()() as the type of a function with empty Parameters and an empty (but parenthesized) Result.

For g(func()()()), the initial func()() is similarly parsed as a bodiless function, and the parentheses are added to invoke that function with empty Arguments.

@bcmills bcmills added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 9, 2019
@gopherbot gopherbot removed the NeedsFix The path to resolution is known, but the work has not been done. label Jan 9, 2019
@josharian
Copy link
Contributor Author

Thanks, Bryan. Given that observation I’m going to call this one not worth investigating and close it.

@golang golang locked and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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