cue icon indicating copy to clipboard operation
cue copied to clipboard

cmd/cue: get go panics when built with Go 1.21 and used with cmd/go 1.22

Open ikawaha opened this issue 4 months ago • 11 comments

What version of CUE are you using (cue version)?

$ cue version
cue version v0.7.0

go version go1.21.5
      -buildmode exe
       -compiler gc
       -trimpath true
  DefaultGODEBUG panicnil=1
     CGO_ENABLED 1
          GOARCH arm64
            GOOS darwin

Does this issue reproduce with the latest stable release?

Yes, it reproduces with the latest stable release.

What did you do?

I've discovered an issue where executing cue get go results in a panic when it targets a Go module at version 1.22.0.

I've prepared two repositories, one with a go.mod file set to Go version 1.22.0 and another set to Go version 1.21.0. Each repository only defines a single constant. I run cue get go results in a panic when it targets a Go module at version 1.22.0.

repository go.mod cue get go
https://github.com/ikawaha/cuegetgosample go 1.21.0 OK
https://github.com/ikawaha/cuepanicsample go 1.22.0 PANIC!

What did you expect to see?

$ go get github.com/ikawaha/cuegetgosample && cue get go github.com/ikawaha/cuegetgosample

go: downloading github.com/ikawaha/cuegetgosample v0.0.0-20240209122316-7722e486d3de
go: added github.com/ikawaha/cuegetgosample v0.0.0-20240209122316-7722e486d3de

$ tree cue.mod/
cue.mod/
└── gen
    └── github.com
        └── ikawaha
            └── cuegetgosample
                └── sample_go_gen.cue

What did you see instead?

$ go get github.com/ikawaha/cuepanicsample && cue get go github.com/ikawaha/cuepanicsample

go: downloading github.com/ikawaha/cuepanicsample v0.0.0-20240209121617-0d013f9d2ed6
go: added github.com/ikawaha/cuepanicsample v0.0.0-20240209121617-0d013f9d2ed6
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x10151d778]

goroutine 1 [running]:
cuelang.org/go/cmd/cue/cmd.recoverError(0x1400061fe60)
	cuelang.org/go/cmd/cue/cmd/root.go:323 +0x94
panic({0x10174e420?, 0x101d4e7e0?})
	runtime/panic.go:914 +0x218
cuelang.org/go/cmd/cue/cmd.(*extractor).recordConsts(0x14000360900, 0x14000272180?)
	cuelang.org/go/cmd/cue/cmd/get_go.go:621 +0x108
cuelang.org/go/cmd/cue/cmd.(*extractor).extractPkg(0x14000360900, {0x14000036064, 0x17}, 0x14000272180)
	cuelang.org/go/cmd/cue/cmd/get_go.go:447 +0xc94
cuelang.org/go/cmd/cue/cmd.extract(0x140004f1680, {0x140005242a0, 0x1, 0x1})
	cuelang.org/go/cmd/cue/cmd/get_go.go:416 +0x2f8
cuelang.org/go/cmd/cue/cmd.newGoCmd.mkRunE.func1(0x140004fdf00?, {0x140005242a0, 0x1, 0x1})
	cuelang.org/go/cmd/cue/cmd/root.go:92 +0x90
github.com/spf13/cobra.(*Command).execute(0x1400050d500, {0x14000524260, 0x1, 0x1})
	github.com/spf13/[email protected]/command.go:940 +0x66c
github.com/spf13/cobra.(*Command).ExecuteC(0x14000447800)
	github.com/spf13/[email protected]/command.go:1068 +0x320
github.com/spf13/cobra.(*Command).Execute(...)
	github.com/spf13/[email protected]/command.go:992
cuelang.org/go/cmd/cue/cmd.(*Command).Run(0x140004f1680, {0x3?, 0x3?})
	cuelang.org/go/cmd/cue/cmd/root.go:308 +0x5c
cuelang.org/go/cmd/cue/cmd.Main()
	cuelang.org/go/cmd/cue/cmd/root.go:236 +0x74
main.main()
	cuelang.org/go/cmd/cue/main.go:24 +0x1c

ikawaha avatar Feb 09 '24 12:02 ikawaha