cmd/compile: ICE assertion failed with append(nil, "string"...)
Opened this issue · 6 comments
Go version
go version go1.25.4 darwin/arm64
Output of go env in your module/workspace:
-What did you do?
This is nonsense code, obviously. But the panic happened while doing real work and just having my code in a temporarily broken state as I was rewriting parts of it, which had gopls crash. Minimal repro:
package main
func main() {
s := "hello"
msg := append(nil, s...)
print(msg)
}What did you see happen?
gopls crash consistently, so I also tried go run
go run main.go
# command-line-arguments
<unknown line number>: internal compiler error: panic: cmd/compile/internal/types2/builtins.go:1093: assertion failed
Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
What did you expect to see?
A compiler error without the panic. 1.24 seems to do the right thing:
go version
go version go1.24.2 darwin/arm64
go run main.go
# command-line-arguments
./main.go:5:16: first argument to append must be a slice; have untyped nil
Related Issues
- x/tools/gopls: panic in deslice when completing unknown type in append #38091 (closed)
- cmd/compile: type assertion panic in types2.(*Checker).instantiatedType (1.24rc1) #71250 (closed)
- x/tools/gopls: completion: failed type assertion in inferExpectedTypeArg #70889 (closed)
- cmd/compile: internal error on call with parenthesized builtin #63436 (closed)
- cmd/compile: internal compiler error: panic during prove #68816 (closed)
- cmd/compile: internal compiler error: not lowered: v108, Zero SSA PTR SSA #59174 (closed)
- x/tools/gopls: Completion: failed type assertion in completer.item #71044 (closed)
- go/types, types2: gopls crash in recordTypeAndValue #51658 (closed)
- go/types,types2: internal compiler error: panic: cmd/compile/internal/types2/check.go:595: assertion failed #66878 (closed)
- cmd/compile: internal compiler error: 'f': value .autotmp_1 (nil) incorrectly live at entry #61778 (closed)
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
cc @golang/compiler @mrkfrmn @griesemer
Thanks, @anderseknert, for reporting and especially for providing the minimal repro, really appreciated.
I will take care of this.
Quick follow-up: this code is not valid because the first argument to append must be a slice, it cannot be the predeclared identifier nil, but obviously this error should be reported rather than leading to a crash.
It appears that this is a regression from 1.24 where this used to work as expected (playground).
Thanks Robert! Indeed, I did not expect the code to compile. I only noticed because gopls crashed immediately on saving the file, and then again when I restarted it. I had done some work involving AppendText methods, which do accept nil... and so when moving things around later I think that's how a nil ended up in a regular append.
Change https://go.dev/cl/718860 mentions this issue: go/types, types2: first argument to append must never be be nil