Skip to content

Commit

Permalink
fix: correct behavior for rune and byte types
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes committed Feb 9, 2020
1 parent 812e55b commit 902af47
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
11 changes: 11 additions & 0 deletions _test/type16.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import "fmt"

func main() {
a := uint8(15) ^ byte(0)
fmt.Printf("%T %v\n", a, a)
}

// Output:
// uint8 15
11 changes: 11 additions & 0 deletions _test/type17.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package main

import "fmt"

func main() {
a := int32(15) ^ rune(0)
fmt.Printf("%T %v\n", a, a)
}

// Output:
// int32 15
4 changes: 2 additions & 2 deletions interp/interp.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func initUniverse() *scope {
sc := &scope{global: true, sym: map[string]*symbol{
// predefined Go types
"bool": {kind: typeSym, typ: &itype{cat: boolT, name: "bool"}},
"byte": {kind: typeSym, typ: &itype{cat: byteT, name: "byte"}},
"byte": {kind: typeSym, typ: &itype{cat: uint8T, name: "uint8"}},
"complex64": {kind: typeSym, typ: &itype{cat: complex64T, name: "complex64"}},
"complex128": {kind: typeSym, typ: &itype{cat: complex128T, name: "complex128"}},
"error": {kind: typeSym, typ: &itype{cat: errorT, name: "error"}},
Expand All @@ -228,7 +228,7 @@ func initUniverse() *scope {
"int32": {kind: typeSym, typ: &itype{cat: int32T, name: "int32"}},
"int64": {kind: typeSym, typ: &itype{cat: int64T, name: "int64"}},
"interface{}": {kind: typeSym, typ: &itype{cat: interfaceT}},
"rune": {kind: typeSym, typ: &itype{cat: runeT, name: "rune"}},
"rune": {kind: typeSym, typ: &itype{cat: int32T, name: "int32"}},
"string": {kind: typeSym, typ: &itype{cat: stringT, name: "string"}},
"uint": {kind: typeSym, typ: &itype{cat: uintT, name: "uint"}},
"uint8": {kind: typeSym, typ: &itype{cat: uint8T, name: "uint8"}},
Expand Down
14 changes: 4 additions & 10 deletions interp/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const (
binPkgT
boolT
builtinT
byteT
chanT
complex64T
complex128T
Expand All @@ -33,7 +32,6 @@ const (
int64T
mapT
ptrT
runeT
srcPkgT
stringT
structT
Expand All @@ -54,7 +52,6 @@ var cats = [...]string{
arrayT: "arrayT",
binT: "binT",
binPkgT: "binPkgT",
byteT: "byteT",
boolT: "boolT",
builtinT: "builtinT",
chanT: "chanT",
Expand All @@ -72,7 +69,6 @@ var cats = [...]string{
int64T: "int64T",
mapT: "mapT",
ptrT: "ptrT",
runeT: "runeT",
srcPkgT: "srcPkgT",
stringT: "stringT",
structT: "structT",
Expand Down Expand Up @@ -200,8 +196,8 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) {
t.cat = boolT
t.name = "bool"
case byte:
t.cat = byteT
t.name = "byte"
t.cat = uint8T
t.name = "uint8"
t.untyped = true
case complex64:
t.cat = complex64T
Expand All @@ -227,8 +223,8 @@ func nodeType(interp *Interpreter, sc *scope, n *node) (*itype, error) {
t.name = "uint"
t.untyped = true
case rune:
t.cat = runeT
t.name = "rune"
t.cat = int32T
t.name = "int32"
t.untyped = true
case string:
t.cat = stringT
Expand Down Expand Up @@ -594,7 +590,6 @@ var zeroValues [maxT]reflect.Value

func init() {
zeroValues[boolT] = reflect.ValueOf(false)
zeroValues[byteT] = reflect.ValueOf(byte(0))
zeroValues[complex64T] = reflect.ValueOf(complex64(0))
zeroValues[complex128T] = reflect.ValueOf(complex128(0))
zeroValues[errorT] = reflect.ValueOf(new(error)).Elem()
Expand All @@ -605,7 +600,6 @@ func init() {
zeroValues[int16T] = reflect.ValueOf(int16(0))
zeroValues[int32T] = reflect.ValueOf(int32(0))
zeroValues[int64T] = reflect.ValueOf(int64(0))
zeroValues[runeT] = reflect.ValueOf(rune(0))
zeroValues[stringT] = reflect.ValueOf("")
zeroValues[uintT] = reflect.ValueOf(uint(0))
zeroValues[uint8T] = reflect.ValueOf(uint8(0))
Expand Down

0 comments on commit 902af47

Please sign in to comment.