You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What steps will reproduce the problem?
Compile and run:
package main
import (
"container/vector";
"fmt"
)
func main() {
x := vector.NewStringVector(2);
x.Push("hello ");
x.Push("world");
for s := range(x.Data()) {
fmt.Print(s)
}
}
What is the expected output? What do you see instead?
It should print "hello world". Instead:
$ ./8.out
interface is nil, not string
throw: interface conversion
panic PC=0xa4f10
throw+0x46 /Users/skybrian/go/src/pkg/runtime/runtime.c:74
throw(0x4839f, 0x35c4c)
runtime·ifaceE2T+0x48 /Users/skybrian/go/src/pkg/runtime/iface.c:262
runtime·ifaceE2T(0x4816c, 0x0, 0x0)
vector·*StringVector·Data+0xd4
/Users/skybrian/go/src/pkg/container/vector/stringvector.go:42
vector·*StringVector·Data(0xa12b0, 0x48014, 0x5)
main·main+0x65 /Users/skybrian/tmp/bug.go:12
main·main()
mainstart+0xf /Users/skybrian/go/src/pkg/runtime/386/asm.s:81
mainstart()
goexit /Users/skybrian/go/src/pkg/runtime/proc.c:135
goexit()
What is your $GOOS? $GOARCH?
$ echo $GOOS $GOARCH
darwin 386
Which revision are you using? (hg identify)
$ hg identify
44699e529c44+ tip
The text was updated successfully, but these errors were encountered:
There are two issues here:
1) After allocating a new vector with NewStringVector(2), that vector already contains 2
elements. Printing it
should print 4 strings ("", "", "hello ", "world").
2) StringVector (and IntVector) is not correctly initializing elements that are added
implicitly as part of a
resize.
Will fix this by changing the vector interface:
- remove NewXVector since its parameter is confusing and new(vector.XVector) is a better
idiom to use
- rename Init to Resize with an extra capacity parameter
by bslesinsky:
The text was updated successfully, but these errors were encountered: