// Regression: `var a, b T = x, y` gives each name its own value. stage4 built // the value list once and stored one value to every name - the first in the // function-scope path, the last in the package-scope path - which is what // broke `var pow, sq uint32 = 1, PrimeRK` in bytealg.HashStrBytes: the // rolling-hash factor came out wrong and bytealg.IndexRabinKarp answered -1 // for needles that are present, so bytes.Index could miss a present substring. package main import "fmt" // The package-scope form goes through the variable initializer function, a // different builder path from the function-scope form below. Only the // []byte("literal") form may carry an initializer at package scope - the loader // demotes it to a constant and both compilers allow it - so the numeric pairs // sit inside main(), which is the other path this regression covers. var gs1, gs2 []byte = []byte("x"), []byte("yz") func main() { if len(gs1) != 1 || len(gs2) != 2 { panic("package slice pair") } var g1, g2 int32 = 3, 4 var gu1, gu2 uint32 = 1, 16777619 var gf1, gf2 float64 = 1.5, 2.5 if g1 != 3 || g2 != 4 { panic("int32 pair") } if gu1 != 1 || gu2 != 16777619 { panic("uint32 pair") } if gf1 != 1.5 || gf2 != 2.5 { panic("float64 pair") } var a, b int32 = 3, 4 if a != 3 || b != 4 { panic("int32 pair") } var pow, sq uint32 = 1, 16777619 if pow != 1 || sq != 16777619 { panic("uint32 pair") } var f, g float64 = 1.5, 2.5 if f != 1.5 || g != 2.5 { panic("float64 pair") } var s, t []byte = []byte("x"), []byte("yz") if len(s) != 1 || len(t) != 2 { panic("slice pair") } // The same shape inside a loop body, which is where HashStrBytes uses it. total := int32(0) for k := int32(0); k < 3; k++ { var p, q int32 = k, k + 10 total += p + q } if total != 3+33 { panic("loop pair") } fmt.Println("ok") }