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
Closed

cmd/compile: incorrect column reported for invalid struct field names #24339

dhowden opened this issue Mar 10, 2018 · 4 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dhowden
Copy link
Contributor

dhowden 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
Copy link
Member

mvdan 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
Copy link
Member

mvdan commented Mar 10, 2018

Found the issue now; it's #16943.

@mvdan mvdan added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. 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
@ianlancetaylor ianlancetaylor added the NeedsFix The path to resolution is known, but the work has not been done. label Mar 12, 2018
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Mar 12, 2018
@griesemer
Copy link
Contributor

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

@gopherbot
Copy link
Contributor

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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants