interp: fix default types for runes
When using an untyped rune in an interface, the default type was blindly untyping it. This fixes this issue. Fixes #1238
This commit is contained in:
22
_test/rune2.go
Normal file
22
_test/rune2.go
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
const majorVersion = '2'
|
||||||
|
|
||||||
|
type hashed struct {
|
||||||
|
major byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
fmt.Println(majorVersion)
|
||||||
|
|
||||||
|
p := new(hashed)
|
||||||
|
p.major = majorVersion
|
||||||
|
|
||||||
|
fmt.Println(p)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// 50
|
||||||
|
// &{50}
|
||||||
@@ -1773,15 +1773,19 @@ func (t *itype) defaultType(v reflect.Value, sc *scope) *itype {
|
|||||||
|
|
||||||
typ := t
|
typ := t
|
||||||
// The default type can also be derived from a constant value.
|
// The default type can also be derived from a constant value.
|
||||||
if v.IsValid() && t.TypeOf().Implements(constVal) {
|
if v.IsValid() && v.Type().Implements(constVal) {
|
||||||
// TODO: find a way to get actual types here
|
|
||||||
switch v.Interface().(constant.Value).Kind() {
|
switch v.Interface().(constant.Value).Kind() {
|
||||||
case constant.String:
|
case constant.String:
|
||||||
typ = sc.getType("string")
|
typ = sc.getType("string")
|
||||||
case constant.Bool:
|
case constant.Bool:
|
||||||
typ = sc.getType("bool")
|
typ = sc.getType("bool")
|
||||||
case constant.Int:
|
case constant.Int:
|
||||||
typ = sc.getType("int")
|
switch t.cat {
|
||||||
|
case int32T:
|
||||||
|
typ = sc.getType("int32")
|
||||||
|
default:
|
||||||
|
typ = sc.getType("int")
|
||||||
|
}
|
||||||
case constant.Float:
|
case constant.Float:
|
||||||
typ = sc.getType("float64")
|
typ = sc.getType("float64")
|
||||||
case constant.Complex:
|
case constant.Complex:
|
||||||
|
|||||||
Reference in New Issue
Block a user