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
dev.go2go: can take address from map indexing when map inside a type list #42616
Comments
The bug here is that type checker should report an error, but does not. Note that we don't expect to continue to support the dev.go2go branch. But we should make sure that the current type checking code doesn't accept this code. Thanks. |
@tdakkota Thanks for finding this and locating the source of the bug! Very helpful. Note that changing the mode to Fix forthcoming. |
As an aside, there's another bug in this code: If we have a map with a key that's not an integer, we cannot index that map. |
Change https://golang.org/cl/270657 mentions this issue: |
…t by maps For instance, given a constraint interface { type []E, map[K]E } and a variable x of type parameter type constraint by above constraint, the index expression x[i] is only permitted if K is an integer type. Also, &x[i] is not permitted if the type list contains a map type since map index expressions are not addressable. Finally, if the type list contains only compatible map types, the index expression x[i] can be used in a comma-ok assignment. Fixes #42616. Change-Id: I6287de47619acee25efbcd73a7b04b835d26a885 Reviewed-on: https://go-review.googlesource.com/c/go/+/270657 Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This is now fixed on the go2go playground. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
n/a
What operating system and processor architecture are you using (
go env
)?What did you do?
https://go2goplay.golang.org/p/bq7UO-0NYT9
That code passes
go2go
type checker.Error is printing when go1 compiler tries to compile translated code.
This bug is caused by:
go/src/go/types/expr.go
Lines 1402 to 1437 in 2298dab
There are:
x.mode
should bemapindex
if type list contains amap
, because in that case index expression is not addressable.Same on
dev.typeparams
go/src/cmd/compile/internal/types2/expr.go
Lines 1510 to 1512 in 6877ee1
What did you expect to see?
An error like
cannot take the address of s[0]
fromgo2go
.Or, maybe,
go2
will allow to take an address from map indexing.What did you see instead?
Code passes
go2go
type checker.The text was updated successfully, but these errors were encountered: