golang/go

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

Chiusa

#28.053 aperta il 6 ott 2018

 (13 commenti) (0 reazioni) (1 assegnatario)Go (19.008 fork)batch import
BadErrorMessageFixPendingcompiler/runtimehelp wanted

Metriche repository

Star
 (133.883 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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).

Guida contributor