interp: fix type string extraction for wrapped constants

Fixes #1089.
This commit is contained in:
Marc Vertes
2021-04-29 18:08:03 +02:00
committed by GitHub
parent 5530eca17d
commit 5f8be70066
2 changed files with 37 additions and 0 deletions

View File

@@ -1172,6 +1172,10 @@ func (t *itype) id() (res string) {
}
res += "}"
case valueT:
if isConstantValue(t.rtype) {
res = constTypeString(t.rtype)
break
}
res = ""
if t.rtype.PkgPath() != "" {
res += t.rtype.PkgPath() + "."
@@ -1183,6 +1187,26 @@ func (t *itype) id() (res string) {
return res
}
func constTypeString(t reflect.Type) (s string) {
cv, ok := reflect.New(t).Elem().Interface().(constant.Value)
if !ok {
return
}
switch cv.Kind() {
case constant.Bool:
s = "bool"
case constant.Int:
s = "int"
case constant.String:
s = "string"
case constant.Float:
s = "float64"
case constant.Complex:
s = "complex128"
}
return
}
// zero instantiates and return a zero value object for the given type during execution.
func (t *itype) zero() (v reflect.Value, err error) {
if t, err = t.finalize(); err != nil {