fix: switch always compare like types

This commit is contained in:
Nicholas Wiersma
2020-07-02 23:35:03 +02:00
committed by GitHub
parent a15ecb7176
commit 1f514e63a8
2 changed files with 34 additions and 1 deletions

28
_test/switch38.go Normal file
View 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

View File

@@ -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
}
}