summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-05-28 22:00:01 +0200
committerGitHub <noreply@github.com>2019-05-28 22:00:01 +0200
commite68adca0c971d911e484a81effc516afc0287bae (patch)
treedd9bfbd9adc80cc15c97d488e14d8c5a5997bd93
parent8bb1a6b04189b6c0f7438ac1b1c17099789f2bd6 (diff)
downloadNim-e68adca0c971d911e484a81effc516afc0287bae.tar.gz
fixes #6777 (#11347)
-rw-r--r--compiler/semstmts.nim3
-rw-r--r--tests/method/treturn_var_t.nim25
2 files changed, 26 insertions, 2 deletions
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)
+