Closed xkortex closed 4 years ago
This is an expected behavior and hard to fix.
package main
import "strings"
import "bytes"
func main() {
const encodeStd = "aBcDeFgHkMnRtUwY"
var encodeSlice = []byte(strings.ToLower(encodeStd))
var fromHexChar = func (c []byte) (byte, bool) {
val := bytes.Index(encodeSlice, c)
if val >= 0 {
return byte(val), true
}
return 0, false
}
fromHexChar([]byte("a"))
}
compiles while
package main
import "strings"
import "bytes"
func main() {
const encodeStd = "aBcDeFgHkMnRtUwY"
var encodeSlice = []byte(strings.ToLower(encodeStd))
_ = encodeSlice
fromHexChar([]byte("a"))
}
func fromHexChar(c []byte) (byte, bool) {
val := bytes.Index(encodeSlice, c)
if val >= 0 {
return byte(val), true
}
return 0, false
}
not.
Hi,
I observe
undefined: encodedSlice
with the following code:works fine, then
fails with
undefined: encodedSlice
. Yet, usingvar foo = func(blah){}
notation works:Is this a bug or expected behavior?