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
This is a fix to #1569 . Thanks to @thehowl for identifying this issue
and providing a thorough and insightful analysis.
Here is an further analysis based on #1569 :
```go
package main
func main() {
{
b := []byte("ABCDEFGHIJKL")
a := b
println(&a[0] == &a[0])
}
}
```
this comparison would be false too.
The root cause for this is the way pointer values is obtained and
compared, e.g.
```go
package main
func main() {
c := []byte{'A'}
a := c
println(&c[0])
println(&c[0] == &a[0])
}
```
in this code snippet, the address of the c[0], (&c[0]) is obtained from
this:
```go
ev := fillValueTV(store, &av.List[ii]) // by reference
```
that is a reference to the element of the underlying list of arrayValue,
in case like this:
```go
package main
func main() {
{
b := []byte("ABCDEFGHIJKL")
a := b
println(&a[0] == &a[0])
}
}
```
the address is obtained by
```go
bv := &TypedValue{ // heap alloc, so need to compare value rather than pointer in isEql(), line 482
T: DataByteType,
V: DataByteValue{
Base: av,
Index: ii,
ElemType: et,
},
}
```
that is a new allocated *TV, which implies the value of it would not be
same within the first and second & operation.
So we should actually compare the concrete value rather than the
pointers for this case.
Before you ask: yes, this is specifically byte slices which are created as a result of string conversion.
The text was updated successfully, but these errors were encountered: