fix: correct type setting for rune characters (#61)
This commit is contained in:
committed by
Ludovic Fernandez
parent
63732d4326
commit
0ab97e661f
37
_test/rune0.go
Normal file
37
_test/rune0.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
a := 'r'
|
||||
a += 'g'
|
||||
fmt.Printf("a: %v %T", a, a)
|
||||
fmt.Println()
|
||||
|
||||
b := 'r'
|
||||
b -= 'g'
|
||||
fmt.Printf("b: %v %T", b, b)
|
||||
fmt.Println()
|
||||
|
||||
c := 'r'
|
||||
c *= 'g'
|
||||
fmt.Printf("c: %v %T", c, c)
|
||||
fmt.Println()
|
||||
|
||||
d := 'r'
|
||||
d /= 'g'
|
||||
fmt.Printf("d: %v %T", d, d)
|
||||
fmt.Println()
|
||||
|
||||
e := 'r'
|
||||
e %= 'g'
|
||||
fmt.Printf("e: %v %T", e, e)
|
||||
fmt.Println()
|
||||
}
|
||||
|
||||
// Output:
|
||||
// a: 217 int32
|
||||
// b: 11 int32
|
||||
// c: 11742 int32
|
||||
// d: 1 int32
|
||||
// e: 11 int32
|
||||
@@ -465,7 +465,7 @@ func (interp *Interpreter) ast(src, name string) (string, *Node, error) {
|
||||
n.ident = a.Value
|
||||
switch a.Kind {
|
||||
case token.CHAR:
|
||||
n.val = a.Value[1]
|
||||
n.val = rune(a.Value[1])
|
||||
case token.FLOAT:
|
||||
n.val, _ = strconv.ParseFloat(a.Value, 64)
|
||||
case token.IMAG:
|
||||
|
||||
@@ -4102,6 +4102,54 @@ func main() {
|
||||
// 22
|
||||
}
|
||||
|
||||
func Example_rune0() {
|
||||
src := `
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
a := 'r'
|
||||
a += 'g'
|
||||
fmt.Printf("a: %v %T", a, a)
|
||||
fmt.Println()
|
||||
|
||||
b := 'r'
|
||||
b -= 'g'
|
||||
fmt.Printf("b: %v %T", b, b)
|
||||
fmt.Println()
|
||||
|
||||
c := 'r'
|
||||
c *= 'g'
|
||||
fmt.Printf("c: %v %T", c, c)
|
||||
fmt.Println()
|
||||
|
||||
d := 'r'
|
||||
d /= 'g'
|
||||
fmt.Printf("d: %v %T", d, d)
|
||||
fmt.Println()
|
||||
|
||||
e := 'r'
|
||||
e %= 'g'
|
||||
fmt.Printf("e: %v %T", e, e)
|
||||
fmt.Println()
|
||||
}
|
||||
`
|
||||
i := interp.New(interp.Opt{Entry: "main"})
|
||||
i.Use(stdlib.Value, stdlib.Type)
|
||||
_, err := i.Eval(src)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Output:
|
||||
// a: 217 int32
|
||||
// b: 11 int32
|
||||
// c: 11742 int32
|
||||
// d: 1 int32
|
||||
// e: 11 int32
|
||||
}
|
||||
|
||||
func Example_scope0() {
|
||||
src := `
|
||||
package main
|
||||
|
||||
@@ -174,6 +174,9 @@ func nodeType(interp *Interpreter, scope *Scope, n *Node) (*Type, error) {
|
||||
case int:
|
||||
t.cat = IntT
|
||||
t.untyped = true
|
||||
case rune:
|
||||
t.cat = RuneT
|
||||
t.untyped = true
|
||||
case string:
|
||||
t.cat = StringT
|
||||
t.untyped = true
|
||||
|
||||
Reference in New Issue
Block a user