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

6g doesn't accept non-parenthesized function literal invocation as if statement condition #1685

Closed
gopherbot opened this issue Apr 12, 2011 · 7 comments

Comments

@gopherbot
Copy link
Contributor

by juhanipm:

gofmt breaks working code by removing required parens from the input program.
see below example.

What steps will reproduce the problem?
1. run gofmt for the following program
`
package main

func main() {
    if (func() bool {
        // in func()
        return true
    }()) {
        // in if
    }
}

`

What is the expected output?
possibly something like this:
`
package main

func main() {
    if (func() bool {
        // in func()
        return true
    }()) {
        // in if
    }
}

`

What do you see instead?
`
package main

func main() {
    if func() bool {
        // in func()
        return true
    }() {
        // in if
    }
}

`

Which revision are you using?  (hg identify)
fe2421ba8894 tip
@gopherbot
Copy link
Contributor Author

Comment 1 by juhanipm:

sorry for the issue spam.
google code gave me 500 Server error message so I thought it didn't go through at first.

@robpike
Copy link
Contributor

robpike commented Apr 12, 2011

Comment 2:

Owner changed to @griesemer.

Status changed to Accepted.

@robpike
Copy link
Contributor

robpike commented Apr 12, 2011

Comment 3:

Issue #1686 has been merged into this issue.

@robpike
Copy link
Contributor

robpike commented Apr 12, 2011

Comment 4:

Issue #1687 has been merged into this issue.

@robpike
Copy link
Contributor

robpike commented Apr 12, 2011

Comment 5:

Issue #1688 has been merged into this issue.

@griesemer
Copy link
Contributor

Comment 6:

This is a 6g bug. Both gofmt and gccgo accept all these versions below:
package main
func main() {
    // version 1
    if func() bool { return true } () {
        println("hi 1")
    }
    // version 2
    if (func() bool { return true }) () {
        println("hi 2")
    }
    // version 3
    if (func() bool { return true } ()) {
        println("hi 3")
    }
}
6g complains about version 1; but there is no parsing ambiguity and it is legal
according to the spec.
Note that gofmt doesn't remove the parentheses around the function literal in version 2
(because it is not aggressively removing all parentheses where not needed at the
moment), so writing the code as in version 2 can serve as a temporary work-around for 6g.

Labels changed: added compilerbug.

Owner changed to @rsc.

@rsc
Copy link
Contributor

rsc commented Apr 14, 2011

Comment 7:

This issue was closed by revision 017e73c.

Status changed to Fixed.

This issue was closed.
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