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

embed: 1.17 rejects types with underlying type []byte #47735

Closed
tnozicka opened this issue Aug 17, 2021 · 9 comments
Closed

embed: 1.17 rejects types with underlying type []byte #47735

tnozicka opened this issue Aug 17, 2021 · 9 comments
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@tnozicka
Copy link

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

$ go version
go version go1.17 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/tnozicka/.cache/go-build"
GOENV="/home/tnozicka/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/tnozicka/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/tnozicka/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/home/tnozicka/lib/go1.17"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/home/tnozicka/lib/go1.17/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/tnozicka/go/src/github.com/scylladb/scylla-operator/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build318278898=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Updated go from 1.16.7 to 1.17 and the following code stopped compiling

var (
	//go:embed "basic.scyllacluster.yaml"
	BasicScyllaCluster ScyllaCluster
)

type ScyllaCluster []byte

func (sc ScyllaCluster) ReadOrFail() *scyllav1.ScyllaCluster {
	obj, _, err := scheme.Codecs.UniversalDeserializer().Decode(sc, nil, nil)
	o.Expect(err).NotTo(o.HaveOccurred())

	return obj.(*scyllav1.ScyllaCluster)
}

What did you expect to see?

No compile error as it was with 1.16.7 (and previous versions).

What did you see instead?

go:embed cannot apply to var of type ScyllaCluster
@sten4eg
Copy link

sten4eg commented Aug 17, 2021

Type alias is
type ScyllaCluster = []byte

@seankhliao
Copy link
Member

It is only documented to only work with string or []byte: https://pkg.go.dev/embed#hdr-Directives

The type of the variable must be a string type, or a slice of a byte type, or FS (or an alias of FS).

type aliases still work

@seankhliao seankhliao changed the title go:embed doesn't compile with type aliases after an upgrade to go1.17 embed: 1.17 rejects types with underlying type []byte Aug 17, 2021
@go101
Copy link

go101 commented Aug 17, 2021

Verified that it works for Go 1.16.

@seankhliao
Copy link
Member

cc @rsc

@seankhliao seankhliao added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Aug 17, 2021
@gopherbot
Copy link

Change https://golang.org/cl/342851 mentions this issue: cmd/compile: allow embed into any byte slice type

korzhao referenced this issue Aug 17, 2021
This merge had two conflicts to resolve:

1. The embed code on master had somewhat substantially diverged, so
this CL tediously backported the changes to dev.regabi. In particular,
I went through all of the embed changes to gc/{embed,noder,syntax}.go
and made sure the analogous code on dev.regabi in noder/noder.go and
staticdata/embed.go mirrors it.

2. The init-cycle reporting code on master was extended slightly to
track already visited declarations to avoid exponential behavior. The
same fix is applied on dev.regabi, just using ir.NameSet instead of
map[ir.Node]bool.

Conflicts:

- src/cmd/compile/internal/gc/embed.go
- src/cmd/compile/internal/gc/noder.go
- src/cmd/compile/internal/gc/syntax.go
- src/cmd/compile/internal/pkginit/initorder.go
- src/embed/internal/embedtest/embed_test.go
- src/go/types/stdlib_test.go

Merge List:

+ 2021-01-22 dab3e5a runtime: switch runtime to libc for openbsd/amd64
+ 2021-01-22 a1b53d8 cmd/go: add documentation for test and xtest fields output by go list
+ 2021-01-22 b268b60 runtime: remove pthread_kill/pthread_self for openbsd
+ 2021-01-22 ec40517 runtime: fix typo in mgcscavenge.go
+ 2021-01-22 7ece3a7 net/http: fix flaky TestDisableKeepAliveUpgrade
+ 2021-01-22 50cba05 time: clarify Timer.Reset behavior on AfterFunc Timers
+ 2021-01-22 cf10e69 doc/go1.16: mention net/http.Transport.GetProxyConnectHeader
+ 2021-01-22 ec1b945 doc/go1.16: mention path/filepath.WalkDir
+ 2021-01-22 11def3d doc/go1.16: mention syscall.AllThreadsSyscall
+ 2021-01-21 07b0235 doc/go1.16: add notes about package-specific fs.FS changes
+ 2021-01-21 e2b4f1f doc/go1.16: minor formatting fix
+ 2021-01-21 9f43a9e doc/go1.16: mention new debug/elf constants
+ 2021-01-21 3c2f11b cmd/go: overwrite program name with full path
+ 2021-01-21 953d1fe all: introduce and use internal/execabs
+ 2021-01-21 b186e4d cmd/go: add test case for cgo CC setting
+ 2021-01-21 5a8a226 cmd/cgo: report exec errors a bit more clearly
+ 2021-01-21 46e2e2e cmd/go: pass resolved CC, GCCGO to cgo
+ 2021-01-21 3d40895 runtime: switch openbsd/arm64 to pthreads
+ 2021-01-21 d95ca91 crypto/elliptic: fix P-224 field reduction
+ 2021-01-20 ecf4ebf cmd/internal/moddeps: check content of all modules in GOROOT
+ 2021-01-20 d2d155d runtime: don't adjust timer pp field in timerWaiting status
+ 2021-01-20 803d18f cmd/go: set Incomplete field on go list output if no files match embed
+ 2021-01-20 6e243ce cmd/go: have go mod vendor copy embedded files in subdirs
+ 2021-01-20 be28e5a cmd/go: fix mod_get_fallback test
+ 2021-01-20 928bda4 runtime: convert openbsd/amd64 locking to libc
+ 2021-01-19 824f2d6 cmd/go: allow go fmt to complete when embedded file is missing
+ 2021-01-19 0575e35 cmd/compile: require 'go 1.16' go.mod line for //go:embed
+ 2021-01-19 ccb2e90 cmd/link: exit before Asmb2 if error
+ 2021-01-19 ca5774a embed: treat uninitialized FS as empty
+ 2021-01-19 d047c91 cmd/link,runtime: switch openbsd/amd64 to pthreads
+ 2021-01-19 61debff runtime: factor out usesLibcall
+ 2021-01-19 9fed39d runtime: factor out mStackIsSystemAllocated
+ 2021-01-18 dbab079 runtime: free Windows event handles after last lock is dropped
+ 2021-01-18 5a8fbb0 os: do not close syscall.Stdin in TestReadStdin
+ 2021-01-15 682a1d2 runtime: detect errors in DuplicateHandle
+ 2021-01-15 9f83418 cmd/link: remove GOROOT write in TestBuildForTvOS
+ 2021-01-15 ec94701 cmd/compile: allow embed into any string or byte slice type
+ 2021-01-15 54198b0 cmd/compile: disallow embed of var inside func
+ 2021-01-15 b386c73 cmd/go: fix go generate docs
+ 2021-01-15 bb5075a syscall: remove RtlGenRandom and move it into internal/syscall
+ 2021-01-15 1deae0b os: invoke processKiller synchronously in testKillProcess
+ 2021-01-15 ff196c3 crypto/x509: update iOS bundled roots to version 55188.40.9
+ 2021-01-14 e125ccd cmd/go: in 'go mod edit', validate versions given to -retract and -exclude
+ 2021-01-14 eb33002 cmd/dist, cmd/go: pass -arch for C compilation on Darwin
+ 2021-01-14 84e8a06 cmd/cgo: remove unnecessary space in cgo export header
+ 2021-01-14 0c86b99 cmd/test2json: document passing -test.paniconexit0
+ 2021-01-14 9135795 cmd/go/internal/load: report positions for embed errors
+ 2021-01-14 d9b79e5 cmd/compile: fix wrong complement for arm64 floating-point comparisons
+ 2021-01-14 c73232d cmd/go/internal/load: refactor setErrorPos to PackageError.setPos
+ 2021-01-14 6aa28d3 go/build: report positions for go:embed directives
+ 2021-01-13 7eb31d9 cmd/go: add hints to more missing sum error messages
+ 2021-01-12 ba76567 cmd/go/internal/modload: delete unused *mvsReqs.next method
+ 2021-01-12 665def2 encoding/asn1: document unmarshaling behavior for IMPLICIT string fields
+ 2021-01-11 81ea89a cmd/go: fix non-script staleness checks interacting badly with GOFLAGS
+ 2021-01-11 7593090 doc: update editors.html for Go 1.16
+ 2021-01-11 c3b4c70 cmd/internal/objfile: don't require runtime.symtab symbol for XCOFF
+ 2021-01-08 59bfc18 cmd/go: add hint to read 'go help vcs' to GOVCS errors
+ 2021-01-08 cd6f3a5 cmd/go: revise 'go help' documentation for modules
+ 2021-01-08 6192b98 cmd/go: make hints in error messages more consistent
+ 2021-01-08 25886cf cmd/go: preserve sums for indirect deps fetched by 'go mod download'
+ 2021-01-08 6250833 runtime/metrics: mark histogram metrics as cumulative
+ 2021-01-08 8f6a9ac runtime/metrics: remove unused StopTheWorld Description field
+ 2021-01-08 6598c65 cmd/compile: fix exponential-time init-cycle reporting
+ 2021-01-08 fefad1d test: fix timeout code for invoking compiler
+ 2021-01-08 6728118 cmd/go: pass signals forward during "go tool"
+ 2021-01-08 e65c543 go/build/constraint: add parser for build tag constraint expressions
+ 2021-01-08 0c5afc4 testing/fstest,os: clarify racy behavior of TestFS
+ 2021-01-08 32afcc9 runtime/metrics: change unit on *-by-size metrics to match bucket unit
+ 2021-01-08 c6513bc io/fs: minor corrections to Glob doc
+ 2021-01-08 304f769 cmd/compile: don't short-circuit copies whose source is volatile
+ 2021-01-08 ae97717 runtime,runtime/metrics: use explicit histogram boundaries
+ 2021-01-08 a9ccd2d go/build: skip string literal while findEmbed
+ 2021-01-08 d92f8ad archive/tar: fix typo in comment
+ 2021-01-08 cab1202 cmd/link: accept extra blocks in TestFallocate
+ 2021-01-08 ee4d322 io/fs: minor corrections to Glob release date
+ 2021-01-08 54bd1cc cmd: update to latest golang.org/x/tools
+ 2021-01-07 9ec21a8 Revert "reflect: support multiple keys in struct tags"
+ 2021-01-07 091414b io/fs: correct WalkDirFunc documentation
+ 2021-01-07 9b55088 doc/go1.16: add release note for disallowing non-ASCII import paths
+ 2021-01-07 fa90aac cmd/compile: fix late expand_calls leaf type for OpStructSelect/OpArraySelect
+ 2021-01-07 7cee66d cmd/go: add documentation for Embed fields in go list output
+ 2021-01-07 e60cffa html/template: attach functions to namespace
+ 2021-01-07 6da2d3b cmd/link: fix typo in asm.go
+ 2021-01-07 df81a15 runtime: check mips64 VDSO clock_gettime return code
+ 2021-01-06 4787e90 crypto/x509: rollback new CertificateRequest fields
+ 2021-01-06 c9658be cmd/go: make module suggestion more friendly
+ 2021-01-06 4c668b2 runtime/metrics: fix panic message for Float64Histogram
+ 2021-01-06 d213170 net/http/httputil: fix deadlock in DumpRequestOut
+ 2021-01-05 3e1e13c cmd/go: set cfg.BuildMod to "readonly" by default with no module root
+ 2021-01-05 0b0d004 cmd/go: pass embedcfg to gccgo if supported
+ 2021-01-05 1b85e7c cmd/go: don't scan gccgo standard library packages for imports
+ 2021-01-05 6b37b15 runtime: don't take allglock in tracebackothers
+ 2021-01-04 9eef49c math/rand: fix typo in comment
+ 2021-01-04 b01fb2a testing/fstest: fix typo in error message
+ 2021-01-01 3dd5867 doc: 2021 is the Year of the Gopher
+ 2020-12-31 95ce805 io/fs: remove darwin/arm64 special condition
+ 2020-12-30 20d0991 lib/time, time/tzdata: update tzdata to 2020f
+ 2020-12-30 ed30173 misc/cgo/testcarchive: remove special flags for Darwin/ARM
+ 2020-12-30 0ae2e03 misc/cgo/test: enable TestCrossPackageTests on darwin/arm64
+ 2020-12-29 780b4de misc/ios: fix wording for command line instructions
+ 2020-12-29 b4a71c9 doc/go1.16: reference misc/ios/README for how to build iOS programs
+ 2020-12-29 f83e0f6 misc/ios: add to README how to build ios executables
+ 2020-12-28 4fd9455 io/fs: fix typo in comment

Change-Id: I2f257bbc5fbb05f15c2d959f8cfe0ce13b083538
@korzhao
Copy link
Contributor

korzhao commented Aug 17, 2021

#43602

I think the reason is that the following merge overrides the original logic.
7e0a81d#diff-93e5af6a86a5745929c27e317b158e986257f9cf4b6904f6e01e13f9bbebaabeL105

@randall77
Copy link
Contributor

Strangely, 1.17 works for named string types, but not named byte slices.

@randall77
Copy link
Contributor

@gopherbot please open a backport issue for 1.17.

@gopherbot
Copy link

Backport issue(s) opened: #47754 (for 1.17).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.

@dmitshur dmitshur added this to the Go1.18 milestone Aug 19, 2021
@golang golang locked and limited conversation to collaborators Aug 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

8 participants