From 9f1f31210a868737c34f77929e27f02061cb14f9 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Tue, 19 Nov 2019 15:22:05 +0100 Subject: [PATCH] fix: automatic type conversion when returning untyped value --- _test/ret7.go | 11 +++++++++++ interp/run.go | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 _test/ret7.go diff --git a/_test/ret7.go b/_test/ret7.go new file mode 100644 index 000000000..968cc66cf --- /dev/null +++ b/_test/ret7.go @@ -0,0 +1,11 @@ +package main + +func one() uint { + return 1 +} +func main() { + println(one()) +} + +// Output: +// 1 diff --git a/interp/run.go b/interp/run.go index 885681c28..f584d833c 100644 --- a/interp/run.go +++ b/interp/run.go @@ -1353,7 +1353,11 @@ func _return(n *node) { case interfaceT: values[i] = genValueInterface(c) default: - values[i] = genValue(c) + if c.typ.untyped { + values[i] = genValueAs(c, def.typ.ret[i].TypeOf()) + } else { + values[i] = genValue(c) + } } }