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: better error message for wrong-cased field name in composite literal #22794

Closed
odeke-em opened this issue Nov 18, 2017 · 3 comments
Labels
FrozenDueToAge help wanted Soon This needs to be done soon. (regressions, serious bugs, outages)

Comments

@odeke-em
Copy link
Member

I was just working on some program in a code base that uses the suffix Id for a field,
but assigning from an struct from another codebase that uses ID instead.
For example given https://play.golang.org/p/9FAMV7mLZE

package main

type it struct {
	ID string
}

func main() {
	i1 := &it{"Foo"}
	if i1.Id != "" {
	}
	i2 := &it{Id: "Bar"}
}

on trying to compile it I get

tmp/sandbox912846952/main.go:9:7: i1.Id undefined (type *it has no field or method Id, but does have ID)
tmp/sandbox912846952/main.go:11:14: unknown field 'Id' in struct literal of type it

Notice the nice hint on line 9 i1.Id undefined (type *it has no field or method Id, but does have ID)
it would be nice(though lengthy) to give a hint on line 14 such as

tmp/sandbox000177384/main.go:11:14: unknown field 'Id' in struct literal of type it (but does have ID)

/cc compiler squad @mdempsky @griesemer @randall77 @rsc.

This is a super low priority issue that I can work on when free(or anyone else is welcome too), ideas and vetoes welcome.

@gopherbot gopherbot added this to the Proposal milestone Nov 18, 2017
@griesemer griesemer changed the title proposal: cmd/compile: invalid but case insensitive field assignments should give hints cmd/compile: better error message for wrong-cased field name in composite literal Nov 18, 2017
@griesemer
Copy link
Contributor

I don't think this needs to be a proposal. Changed.

@griesemer griesemer modified the milestones: Proposal, Soon Nov 18, 2017
@odeke-em
Copy link
Member Author

Hehe, thank you @griesemer :)

@gopherbot
Copy link

Change https://golang.org/cl/78545 mentions this issue: cmd/compile: hint on wrong case-field names in composite literals

@odeke-em odeke-em self-assigned this Nov 18, 2017
@bradfitz bradfitz added the Soon This needs to be done soon. (regressions, serious bugs, outages) label May 17, 2018
@golang golang locked and limited conversation to collaborators May 17, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge help wanted Soon This needs to be done soon. (regressions, serious bugs, outages)
Projects
None yet
Development

No branches or pull requests

4 participants