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/compile: incorrect column reported for invalid struct field names #24339

Closed
dhowden opened this issue Mar 10, 2018 · 4 comments

Comments

Projects
None yet
5 participants
@dhowden
Copy link

commented Mar 10, 2018

Please answer these questions before submitting your issue. Thanks!

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

go1.10

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOOS="darwin"

What did you do?

Tried to compile this (incorrect code):

package main

type Struct struct {}

func main() {
	x := Struct{
		InvalidName: 10,
	}
}

What did you expect to see?

prog.go:7:3: unknown field 'InvalidName' in struct literal of type Struct
	x := Struct{
		InvalidName: 10,
//		^
	}

What did you see instead?

prog.go:7:14: unknown field 'InvalidName' in struct literal of type Struct
	x := Struct{
		InvalidName: 10,
//		           ^
	}

Go Playground: https://play.golang.org/p/-UT1IgmXgQD

@mvdan mvdan changed the title go/parser: incorrect column reported for invalid struct field names cmd/compile: incorrect column reported for invalid struct field names Mar 10, 2018

@mvdan

This comment has been minimized.

Copy link
Member

commented Mar 10, 2018

This does not concern go/parser; rather, this is the compiler. The error comes from gc, and the position from syntax.

I also believe that this is working as intended, as the position of the key-value expression is the position of the colon token. There was an issue where @mdempsky suggested that, in the new syntax package, node positions shouldn't always be their start position. For example, in x + y, the position of the binary arithmetic expression should be the +. However, I can't seem to find that issue right now.

Having said that, I can understand that the error concerns the field name, not the entire key-value expression. Perhaps the error in this case should use the position for the field, and not the entire key-value expression.

Also cc @griesemer.

@mvdan

This comment has been minimized.

Copy link
Member

commented Mar 10, 2018

Found the issue now; it's #16943.

@mvdan mvdan added the NeedsDecision label Mar 10, 2018

@mvdan mvdan modified the milestones: Go1.10.1, Go1.11 Mar 10, 2018

@griesemer griesemer self-assigned this Mar 10, 2018

@griesemer

This comment has been minimized.

Copy link
Contributor

commented Mar 13, 2018

Package syntax provides all the relevant positions here. It's just a matter of using the right one. Will fix.

@gopherbot

This comment has been minimized.

Copy link

commented Mar 13, 2018

Change https://golang.org/cl/100457 mentions this issue: cmd/compile: use key position for key:val elements in composite literals

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.