golang/go

cmd/compile: more helpful "is not a type" error when variable shadows type

Open

#23.065 geöffnet am 9. Dez. 2017

Auf GitHub ansehen
 (8 Kommentare) (8 Reaktionen) (0 zugewiesene Personen)Go (19.008 Forks)batch import
NeedsFixhelp wanted

Repository-Metriken

Stars
 (133.883 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

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

Current playground version.

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

Unknown (plaground).

What did you do?

The following code compiles with fancyMap is not a type errors in both foo and foo2 (playground):

package main

type fancyMap = map[string]string

func foo(fancyMap fancyMap) {
	var _ fancyMap
}

func foo2(fancyMap fancyMap) {
	_ = make(fancyMap)
}

func main() {
}

What did you expect to see?

Successful compilation or a more informative error message.

What did you see instead?

Poor/incorrect error message. Simply renaming the fancyMap variable fixes the problem, but the error message is incorrect: fancyMap is a type.

Apologies if there's an existing issue for this.

Contributor Guide