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: In struct literals, type check outside in rather than inside out. #8659
Milestone
Comments
The basic problem is a type mismatch. I think you're suggesting that when there is a type mismatch between the type of the composite literal and its elements that we should report the error on the type rather than the elements. But sometimes that will be wrong too. How can we know where it would be better to report an error? It's not a rhetorical question; if you can suggest a simple algorithm, perhaps we can implement it. Labels changed: added repo-main, release-none. |
> I think you're suggesting that when there is a type mismatch between the type of the composite literal and its elements that we should report the error on the type rather than the elements. If I understand you correctly, that's not what I'm suggesting. I'm suggesting that we check that the type of the field and the element match before checking that values within the element are correct. In the example code: type Foo struct{ Elem [][]float64 } func main(){ _ = Foo{ Elem: []float64{ // other code}, } } this code is wrong no matter what "other code" contains, because Elem has type [][]float64, but the value has type []float64. I'm suggesting that this be checked before checking that the types within "// other code" are correct. |
rsc
changed the title
cmd/gc: In struct literals, type check outside in rather than inside out.
cmd/compile: In struct literals, type check outside in rather than inside out.
Jun 8, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: