From e42ce877a6469ccc6eb99e1e0f6162aeb6839193 Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 8 Jul 2020 10:45:51 +0200 Subject: [PATCH] fixes #14805 --- compiler/ccgtypes.nim | 2 +- tests/lent/tlent_from_var.nim | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/lent/tlent_from_var.nim diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 11743499d7..fb205110e6 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -279,7 +279,7 @@ proc ccgIntroducedPtr(conf: ConfigRef; s: PSym, retType: PType): bool = result = false # first parameter and return type is 'lent T'? --> use pass by pointer if s.position == 0 and retType != nil and retType.kind == tyLent: - result = true + result = pt.kind != tyVar proc fillResult(conf: ConfigRef; param: PNode) = fillLoc(param.sym.loc, locParam, param, ~"Result", diff --git a/tests/lent/tlent_from_var.nim b/tests/lent/tlent_from_var.nim new file mode 100644 index 0000000000..c8a15b1a13 --- /dev/null +++ b/tests/lent/tlent_from_var.nim @@ -0,0 +1,14 @@ +discard """ + output: "x" +""" + +# bug #14805 + +type Foo = object + a: string + +proc bar(f: var Foo): lent string = + result = f.a + +var foo = Foo(a: "x") +echo bar(foo)