Skip to content

cmd/gc: inlining unparenthesizes struct literals in if statements. #4230

@anacrolix

Description

@anacrolix
Importing a module containing syntax like the following:

type bleh struct {
    hi int
}

func (me bleh) meh() string {
    if me == (bleh{}) { // <- this is bad
        return "0"
    }

Will give an error at the point of import, instead of during compilation at the line of
the actual syntax error.

I've boiled down the problem as small as I can get it here:
https://bitbucket.org/anacrolix/goplay/src/a2ffccb08ad0/bug

What is the expected output?
D:\gopath\src\bitbucket.org\anacrolix\goplay\bug>go build
bitbucket.org/anacrolix/goplay/bug
# bitbucket.org/anacrolix/goplay/bug/dep
d:\gopath\src\bitbucket.org\anacrolix\goplay\bug\dep\dep.go:8: syntax error: unexpected
{ at end of statement

What do you see instead?

D:\gopath\src\bitbucket.org\anacrolix\goplay\bug>go build
bitbucket.org/anacrolix/goplay/bug
# bitbucket.org/anacrolix/goplay/bug
d:\gopath\src\bitbucket.org\anacrolix\goplay\bug\main.go:4: syntax error: unexpected {
at end of statement

Which compiler are you using (5g, 6g, 8g, gccgo)?
8g, go version devel +bc50fc903d6e Thu Oct 11 01:34:26 2012 +0800

Which operating system are you using?
Windoze

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions