diff --git a/_test/const19.go b/_test/const19.go new file mode 100644 index 000000000..764d6d26e --- /dev/null +++ b/_test/const19.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "time" +) + +func get10Hours() time.Duration { + return 10 * time.Hour +} + +func main() { + fmt.Println(get10Hours().String()) +} + +// Output: +// 10h0m0s diff --git a/interp/run.go b/interp/run.go index f29db9dcd..70fa1d369 100644 --- a/interp/run.go +++ b/interp/run.go @@ -1869,7 +1869,10 @@ func _return(n *node) { case 0: n.exec = nil case 1: - if child[0].kind == binaryExpr || isCall(child[0]) { + // This is an optimisation that is applied for binary expressions or function + // calls, but not for (binary) expressions involving const, as the values are not + // stored in the frame in that case. + if !child[0].rval.IsValid() && child[0].kind == binaryExpr || isCall(child[0]) { n.exec = nil } else { v := values[0]