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/go2go: cannot use make(map[int]X) (value of type map[int]X) as map[int]X value in struct literal #39982
Comments
It seems the translator sees 2 types whereas there's only one. package main
type (
Element(type TElem) struct{}
entry(type K comparable) struct{}
Cache(type K comparable) struct {
data map[K]*Element(*entry(K))
}
)
func main() {
_ = Cache(int){}
_ = make(map[int](*Element(*entry(int))))
} gives:
playground: https://go2goplay.golang.org/p/B-cdj3yBgAw Both errors (the one in the top post and this one) might be 2 faces of the same coin. In case they aren't let me know if I should open a different issue. Thanks |
This seems like a failure in the type checker. At least, I don't see why it shouldn't work. |
Definitely a type-checker failure. |
Change https://golang.org/cl/240737 mentions this issue: |
Fixes #39982. Change-Id: I4e7b52c34bf8df63f2063dc2504a8125ca7585a0 Reviewed-on: https://go-review.googlesource.com/c/go/+/240737 Reviewed-by: Robert Griesemer <gri@golang.org>
Fixed on dev.go2go. |
I just tested with 85ed317 and now both listing (top and 2nd comments of this issue) give the same error: $ go tool go2go run issue39982.go2
# command-line-arguments
./issue39982.go2:25: instantiate୦୦Element୦୮1main୮aentry୮8int୮9 redeclared in this block
previous declaration at ./issue39982.go2:29
/home/aurelien/dev/go/bin/go [run issue39982.go] failed: exit status 2 Let me know whether you prefer a new issue for this. |
@arl, thanks for this. I admit I only tested type-checking for this case. Reopening. |
@ianlancetaylor Not sure if this is still a type-checker issue or a translator issue at this point. |
Thanks. Translator is fixed on dev.go2go branch. |
Change https://golang.org/cl/240899 mentions this issue: |
Fixes #39982 Change-Id: Ieb33381716662b44464104e0073a52ab5c19b7c6 Reviewed-on: https://go-review.googlesource.com/c/go/+/240899 Reviewed-by: Ian Lance Taylor <iant@golang.org>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
It does with latest commit of the
dev.go2go
experimental branch: d014fcaWhat operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
A bit of context: I'm currently experimenting with the generics draft by trying to use it to develop a generics cache library.
I compacted the code into a single-file reproducer to make debugging easier but the actual code imports various packages, among which the
list
package of thedev.go2go
source tree (generic replacement forcontainer/list
).The original cache is based off a simple
map
where the value is a*list.Element(*entry(K)
.It does the same on the playground: https://go2goplay.golang.org/p/qoMgsPA5ifd
What did you expect to see?
a successful compilation since the provided map is, AFAICT, of the same type as the
Cache.data
type.What did you see instead?
The error reported above:
The text was updated successfully, but these errors were encountered: