Skip to content

cmd/compile: give better error for composite literal parsing ambiguity #30867

@empijei

Description

@empijei

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

$ go version
go version go1.12 linux/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

type foo struct{}

func main() {
	bar := foo{}
	if bar == foo{} {
		fmt.Println("true")
		return
	}
	fmt.Println("false")
}

Play link

What did you expect to see?

true

What did you see instead?

prog.go:11:18: syntax error: unexpected { at end of statement
prog.go:15:2: syntax error: non-declaration statement outside function body

Please note that adding parentheses works

	if bar == (foo{}) {

Is this intended? If so, shouldn't the compiler give better errors?

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.help wanted

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions