fix: switch always compare like types
This commit is contained in:
28
_test/switch38.go
Normal file
28
_test/switch38.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package main
|
||||
|
||||
func isSeparator(c byte) bool {
|
||||
switch c {
|
||||
case '(', ')', '<', '>', '@', ',', ';', ':', '\\', '"', '/', '[', ']', '?', '=', '{', '}', ' ', '\t':
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func main() {
|
||||
s := "max-age=20"
|
||||
for _, c := range []byte(s) {
|
||||
println(string(c), isSeparator(c))
|
||||
}
|
||||
}
|
||||
|
||||
// Output:
|
||||
// m false
|
||||
// a false
|
||||
// x false
|
||||
// - false
|
||||
// a false
|
||||
// g false
|
||||
// e false
|
||||
// = true
|
||||
// 2 false
|
||||
// 0 false
|
||||
@@ -2309,8 +2309,13 @@ func _case(n *node) {
|
||||
values[i] = genValue(n.child[i])
|
||||
}
|
||||
n.exec = func(f *frame) bltn {
|
||||
v0 := value(f)
|
||||
for _, v := range values {
|
||||
if value(f).Interface() == v(f).Interface() {
|
||||
v1 := v(f)
|
||||
if !v0.Type().AssignableTo(v1.Type()) {
|
||||
v0 = v0.Convert(v1.Type())
|
||||
}
|
||||
if v0.Interface() == v1.Interface() {
|
||||
return tnext
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user