Skip to content

Commit

Permalink
fix: correct isValueUntyped() to handle typed constants
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored and traefiker committed Dec 19, 2019
1 parent e1ac83f commit 3cd3764
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
15 changes: 15 additions & 0 deletions _test/time11.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"fmt"
"time"
)

const df = time.Minute * 30

func main() {
fmt.Printf("df: %v %T\n", df, df)
}

// Output:
// df: 30m0s time.Duration
12 changes: 3 additions & 9 deletions interp/cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,8 +602,6 @@ func (interp *Interpreter) cfg(root *node) ([]*node, error) {
constOp[n.action](n)
}
switch {
//case n.typ != nil && n.typ.cat == BoolT && isAncBranch(n):
// n.findex = -1
case n.rval.IsValid():
n.gen = nop
n.findex = -1
Expand Down Expand Up @@ -1851,14 +1849,10 @@ func arrayTypeLen(n *node) int {

// isValueUntyped returns true if value is untyped
func isValueUntyped(v reflect.Value) bool {
// Consider only untyped constant values.
// Consider only constant values.
if v.CanSet() {
return false
}
// Consider only values of default numerical types.
switch v.Type().Kind() {
case reflect.Int, reflect.Int32, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float64, reflect.Complex128:
return true
}
return false
t := v.Type()
return t.String() == t.Kind().String()
}

0 comments on commit 3cd3764

Please sign in to comment.