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/go: awkward composite literal edge case #45396
Comments
CC @griesemer |
My inclination would be that this shouldn't be valid. More generally, we need to pin down exactly what the currently proposed rules mean when they say "all operations supported by all types in a type set" will be permitted. |
FWIW as just a user without any particular investment in any specific answer to this question, my first intuition told me that this would not be valid because I see four different semantic "operations" here, even though all of them have the same syntax:
However, this did get me thinking about other similar situations where the syntax could be said to overlap even though the semantics might not: type C interface {
type map[int]string, []string, chan string. []int, chan int
}
func f[A C]() A {
return make(A)
}
Which then led me back to ambivalence, because I'm not sure it feels justified to me for Having written this out I find myself doubting whether I've actually added anything to the discussion, because I left feeling far less convinced than I started! But I hope at least the analogy to |
@apparentlymart I think at the end of the day this is the kind of thing we need to explicitly write down in the spec. A{
b1: "a",
b2: "b",
} where |
I want everyone to LOOK, A SQUIRREL before someone else comes in to suggest lua-style I do think this is something that will need a solution but I think that the introduction of generics can survive the inability to memberwise-construct compounds: so I propose completely disallowing it in the initial launch of generics.
might produce the diagnostic
Better to have this omission than to reinvent c++ templates. |
This will not be in the Go1.18 release. Leaving open for future discussion. |
The 1.18 spec now explicitly requires a core type for composite literals. I am going to close this issue as If this is important to change, we need an actual proposal that outlines exactly what should be permitted and what should not be permitted in this case. I'm particularly concerned about mixing index values and struct field names, and to a lesser extent, mixing map and non-map types. These two cases will need to be explored in detail in a proposal. |
In this comment I brought up an edge case for type parameters:
Should this be valid or not?
Note that if
C
contains only one of any of the type list above, the code works for that type.[Edited to bring syntax up to date]
The text was updated successfully, but these errors were encountered: