This commit is contained in:
Araq 2014-12-17 01:11:30 +01:00
commit e9619d7278
3 changed files with 30 additions and 13 deletions

View file

@ -1249,8 +1249,8 @@ proc semAsgn(c: PContext, n: PNode): PNode =
proc semReturn(c: PContext, n: PNode): PNode = proc semReturn(c: PContext, n: PNode): PNode =
result = n result = n
checkSonsLen(n, 1) checkSonsLen(n, 1)
if c.p.owner.kind in {skConverter, skMethod, skProc, skMacro} or if c.p.owner.kind in {skConverter, skMethod, skProc, skMacro,
c.p.owner.kind == skClosureIterator: skClosureIterator}:
if n.sons[0].kind != nkEmpty: if n.sons[0].kind != nkEmpty:
# transform ``return expr`` to ``result = expr; return`` # transform ``return expr`` to ``result = expr; return``
if c.p.resultSym != nil: if c.p.resultSym != nil:

View file

@ -939,17 +939,19 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
# turn explicit 'void' return type into 'nil' because the rest of the # turn explicit 'void' return type into 'nil' because the rest of the
# compiler only checks for 'nil': # compiler only checks for 'nil':
if skipTypes(r, {tyGenericInst}).kind != tyEmpty: if skipTypes(r, {tyGenericInst}).kind != tyEmpty:
if r.sym == nil or sfAnon notin r.sym.flags: # 'auto' as a return type does not imply a generic:
let lifted = liftParamType(c, kind, genericParams, r, "result", if r.kind != tyExpr:
n.sons[0].info) if r.sym == nil or sfAnon notin r.sym.flags:
if lifted != nil: r = lifted let lifted = liftParamType(c, kind, genericParams, r, "result",
r.flags.incl tfRetType n.sons[0].info)
r = skipIntLit(r) if lifted != nil: r = lifted
if kind == skIterator: r.flags.incl tfRetType
# see tchainediterators r = skipIntLit(r)
# in cases like iterator foo(it: iterator): type(it) if kind == skIterator:
# we don't need to change the return type to iter[T] # see tchainediterators
if not r.isInlineIterator: r = newTypeWithSons(c, tyIter, @[r]) # in cases like iterator foo(it: iterator): type(it)
# we don't need to change the return type to iter[T]
if not r.isInlineIterator: r = newTypeWithSons(c, tyIter, @[r])
result.sons[0] = r result.sons[0] = r
res.typ = r res.typ = r

View file

@ -0,0 +1,15 @@
discard """
output: "wof!"
"""
# bug #1659
type Animal = ref object {.inheritable.}
type Dog = ref object of Animal
method say(a: Animal): auto = "wat!"
method say(a: Dog): auto = "wof!"
proc saySomething(a: Animal): auto = a.say()
var a = Dog()
echo saySomething(a)