go: spec: clarify that conversions to slices don't guarantee slice capacity?
What did you do?
Converted a string to a slice of runes then back to a string, and referenced non-existent elements on the slice of runes:
https://play.golang.org/p/MmJNLu6h6FT
What did you expect to see?
A runtime panic with a ‘slice bounds out of range’ error.
What did you see instead?
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
System details
go version go1.10 darwin/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/matt/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/matt/go"
GORACE=""
GOROOT="/opt/boxen/homebrew/Cellar/go/1.10/libexec"
GOTMPDIR=""
GOTOOLDIR="/opt/boxen/homebrew/Cellar/go/1.10/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/k4/_18vs9g119b0q2_p950t0jl00000gn/T/go-build038036646=/tmp/go-build -gno-record-gcc-switches -fno-common"
GOROOT/bin/go version: go version go1.10 darwin/amd64
GOROOT/bin/go tool compile -V: compile version go1.10
uname -v: Darwin Kernel Version 17.4.0: Sun Dec 17 09:19:54 PST 2017; root:xnu-4570.41.2~1/RELEASE_X86_64
ProductName: Mac OS X
ProductVersion: 10.13.3
BuildVersion: 17D47
lldb --version: lldb-900.0.64
Swift-4.0
About this issue
- Original URL
- State: open
- Created 6 years ago
- Comments: 15 (15 by maintainers)
@mdempsky Wow, you’re even more of a rebel than I am.
Considering that escape analysis changes somewhat regularly, I kinda doubt anybody’s relying on this. We’ve never heard anything about it.
As bad as it sounds, there may be existing code that relies on this feature…
Perhaps the spec just needs to say that it doesn’t say anything about the capacity in these cases.
I think that for these conversions the result should be a slice with cap == len. I see no benefit to leaving it unspecified.