From e68adca0c971d911e484a81effc516afc0287bae Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 28 May 2019 22:00:01 +0200 Subject: fixes #6777 (#11347) --- compiler/semstmts.nim | 3 +-- tests/method/treturn_var_t.nim | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/method/treturn_var_t.nim diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 3090bf455..655b9c5c0 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -1883,14 +1883,13 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, c.p.wasForwarded = proto != nil maybeAddResult(c, s, n) - if s.kind == skMethod: semMethodPrototype(c, s, n) - if lfDynamicLib notin s.loc.flags: # no semantic checking for importc: s.ast[bodyPos] = hloBody(c, semProcBody(c, n.sons[bodyPos])) # unfortunately we cannot skip this step when in 'system.compiles' # context as it may even be evaluated in 'system.compiles': trackProc(c, s, s.ast[bodyPos]) + if s.kind == skMethod: semMethodPrototype(c, s, n) else: if (s.typ.sons[0] != nil and kind != skIterator) or kind == skMacro: addDecl(c, newSym(skUnknown, getIdent(c.cache, "result"), nil, n.info)) diff --git a/tests/method/treturn_var_t.nim b/tests/method/treturn_var_t.nim new file mode 100644 index 000000000..91d982902 --- /dev/null +++ b/tests/method/treturn_var_t.nim @@ -0,0 +1,25 @@ +discard """ + output: '''Inh +45''' +""" + +type + Base = ref object of RootObj + field: int + + Inh = ref object of Base + +# bug #6777 +method foo(b: Base): var int {.base.} = + echo "Base" + result = b.field + +method foo(b: Inh): var int = + echo "Inh" + result = b.field + +var x: Base +var y = Inh(field: 45) +x = y +echo foo(x) + -- cgit 1.4.1-2-gfad0