Skip to content

Commit

Permalink
fixes #6777
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed May 28, 2019
1 parent 379916c commit 26ee21f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
25 changes: 25 additions & 0 deletions tests/method/treturn_var_t.nim
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 26ee21f

Please sign in to comment.