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

Comments

Projects
None yet
4 participants
@odeke-em
Copy link
Member

commented Nov 18, 2017

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

@gopherbot gopherbot added the Proposal label 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

This comment has been minimized.

Copy link
Contributor

commented Nov 18, 2017

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

@griesemer griesemer removed the Proposal label Nov 18, 2017

@griesemer griesemer modified the milestones: Proposal, Soon Nov 18, 2017

@odeke-em

This comment has been minimized.

Copy link
Member Author

commented Nov 18, 2017

Hehe, thank you @griesemer :)

@gopherbot

This comment has been minimized.

Copy link

commented Nov 18, 2017

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

@gopherbot gopherbot closed this in 5f29a7a Nov 20, 2017

@bradfitz bradfitz added the Soon 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.
You can’t perform that action at this time.