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: return LITERAL on INDEXMAP when map and key are LITERALs #35763

Closed
Segflow opened this issue Nov 21, 2019 · 2 comments · May be fixed by #35764
Closed

cmd/compile: return LITERAL on INDEXMAP when map and key are LITERALs #35763

Segflow opened this issue Nov 21, 2019 · 2 comments · May be fixed by #35764
Milestone

Comments

@Segflow
Copy link
Contributor

@Segflow Segflow commented Nov 21, 2019

Given

package main
const (
	key = "literalKey"
)
func main() {
	v := map[string]string{
		"literalKey": "v1",
		"anotherkey": "v2",
	}[key]
	_ = v
}

When compiled, the compiler will add the different map initialisations methods and assign the different values, then call mapaccess1.

I believe this should not be the case when the map is an OMAPLIT and the key is a LITERAL defined in the map.

The compiler at compile-time can detect this and change the INDEXMAP operation to LITERAL.

The above code should be similar to this one:

package main
const (
	key = "literalKey"
)
func main() {
	v := "v1"
	_ = v
}

What version of Go are you using (go version)?

$ go version
go version go1.13.4 darwin/amd64
@gopherbot
Copy link

@gopherbot gopherbot commented Nov 21, 2019

Change https://golang.org/cl/208323 mentions this issue: cmd/compile: return LITERAL on INDEXMAP when map and key are LITERALs

@randall77 randall77 added this to the Go1.15 milestone Nov 22, 2019
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Apr 29, 2020

This is a duplicate of #10848.

@mdempsky mdempsky closed this Apr 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.