golang/go

cmd/compile: clearer error message for unkeyed composite literal with unexported field

Geschlossen

#28.053 geöffnet am 06.10.2018

 (13 Kommentare) (0 Reaktionen) (1 zugewiesene Person)Go (19.008 Forks)batch import
BadErrorMessageFixPendingcompiler/runtimehelp wanted

Repository-Metriken

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

Beschreibung

I have a struct:

package df

type SortKey struct {
	Key interface{}
	SortDesc bool
	seriesIndex int
}

From an outside package:

TRY 1

z := df.SortKey{"n", false}

Compiler error: too few values in df.SortKey literal

TRY 2

z := df.SortKey{"n", false, 0}

Compiler error: implicit assignment of unexported field 'seriesIndex' in df.SortKey literal

You can't win. Perhaps it should just be disallowed for Go 2 - It messes up backwards compatibility anyway amongst minor versions of packages (eg. net/http.Request and Context situation).

Contributor Guide