Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fixes #4875
  • Loading branch information
Araq committed Oct 20, 2016
1 parent 4e51b56 commit 7c0fa52
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
36 changes: 18 additions & 18 deletions compiler/semexprs.nim
Expand Up @@ -695,6 +695,22 @@ proc semBracketedMacro(c: PContext; outer, inner: PNode; s: PSym;
else: assert(false)
return

proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode =
result = n
let callee = result.sons[0].sym
case callee.kind
of skMacro: result = semMacroExpr(c, result, orig, callee, flags)
of skTemplate: result = semTemplateExpr(c, result, callee, flags)
else:
semFinishOperands(c, result)
activate(c, result)
fixAbstractType(c, result)
analyseIfAddressTakenInCall(c, result)
if callee.magic != mNone:
result = magicsAfterOverloadResolution(c, result, flags)
if c.inTypeClass == 0:
result = evalAtCompileTime(c, result)

proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
result = nil
checkMinSonsLen(n, 1)
Expand Down Expand Up @@ -773,27 +789,11 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
# See bug #904 of how to trigger it:
return result
#result = afterCallActions(c, result, nOrig, flags)
fixAbstractType(c, result)
analyseIfAddressTakenInCall(c, result)
if result.sons[0].kind == nkSym and result.sons[0].sym.magic != mNone:
result = magicsAfterOverloadResolution(c, result, flags)
result = evalAtCompileTime(c, result)

proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags): PNode =
result = n
let callee = result.sons[0].sym
case callee.kind
of skMacro: result = semMacroExpr(c, result, orig, callee, flags)
of skTemplate: result = semTemplateExpr(c, result, callee, flags)
if result.sons[0].kind == nkSym:
result = afterCallActions(c, result, nOrig, flags)
else:
semFinishOperands(c, result)
activate(c, result)
fixAbstractType(c, result)
analyseIfAddressTakenInCall(c, result)
if callee.magic != mNone:
result = magicsAfterOverloadResolution(c, result, flags)
if c.inTypeClass == 0:
result = evalAtCompileTime(c, result)

proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode =
# this seems to be a hotspot in the compiler!
Expand Down
13 changes: 13 additions & 0 deletions tests/template/tconfusinglocal.nim
@@ -0,0 +1,13 @@

# bug #4875
type Bar = object
mFoo: int

template foo(a: Bar): int = a.mFoo

proc main =
let foo = 5 # Rename this to smth else to make it work
var b: Bar
echo b.foo

main()

0 comments on commit 7c0fa52

Please sign in to comment.