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
The following program should output:
-2
-2
But actually outputs
5
-2
But if you uncomment the commented fmt.Println statement it does produce the right
answers (-2, -2)!
So I guess there's a weird reflect bug.
: hg identify
d6903b7fbff4+ weekly/weekly.2011-04-13
I'm on debian testing 64-bit.
package main
import (
"fmt"
"reflect"
)
func main() {
i := M(5, 1, 2, 3, -2, 4).Int()
fmt.Println(i)
f := M(5.0, 1.0, 2.0, 3.0, -2.0, 4.0).Float()
fmt.Println(f)
}
func M(x interface{}, ys ...interface{}) reflect.Value {
m := reflect.NewValue(x)
k := m.Kind()
for _, y := range ys {
//fmt.Println(m) // Uncomment this and it gives the right answer!
v := reflect.NewValue(y)
switch k {
case reflect.Int: if v.Int() < m.Int() { m.Set(v) }
case reflect.Float64: if v.Float() < m.Float() { m.Set(v) }
}
}
return m
}
The text was updated successfully, but these errors were encountered:
This doesn't have to do with reflect, although the new
reflect changes make the program not run anymore.
I checked out the version that Mark is running on Linux
and can reproduce the problem. It is a compiler optimization bug.
I have a workaround but I want to spend a bit more time looking
for the root cause to make sure I fix the real problem.
The text was updated successfully, but these errors were encountered: