mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-11 22:08:54 +00:00
@@ -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))
|
||||
|
||||
25
tests/method/treturn_var_t.nim
Normal file
25
tests/method/treturn_var_t.nim
Normal file
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user