From bdeaee4a331de99d964386682f49de213b7d7d87 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Mon, 26 Aug 2013 23:43:39 +0300 Subject: [PATCH] fix tnoop This commit requires further investigation. Fixing semExpr(nkCall) once and for all to work with sym-choices and to allow overloading with immediate templates and macros will probably set this straight too. --- compiler/ast.nim | 1 + compiler/semcall.nim | 11 ++++++++--- compiler/semexprs.nim | 8 +++----- tests/reject/tnoop.nim | 11 +++++------ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index b12d586265..4ed44a8fe8 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -354,6 +354,7 @@ type nfTransf, # node has been transformed nfSem # node has been checked for semantics nfDelegate # the call can use a delegator + nfExprCall # this is an attempt to call a regular expression TNodeFlags* = set[TNodeFlag] TTypeFlag* = enum # keep below 32 for efficiency reasons (now: 23) diff --git a/compiler/semcall.nim b/compiler/semcall.nim index 22ee8c0999..643eef0654 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -128,9 +128,14 @@ proc resolveOverloads(c: PContext, n, orig: PNode, pickBest(callOp) if result.state == csEmpty: - errors = @[] - pickBest(f) - NotFoundError(c, n, errors) + if nfExprCall in n.flags: + if c.inCompilesContext > 0 or gErrorCounter == 0: + LocalError(n.info, errExprXCannotBeCalled, + renderTree(n, {renderNoComments})) + else: + errors = @[] + pickBest(f) + NotFoundError(c, n, errors) return if alt.state == csMatch and cmpCandidates(result, alt) == 0 and diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 369b0eb904..a688efc5b3 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -732,14 +732,12 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode = # Now that nkSym does not imply an iteration over the proc/iterator space, # the old ``prc`` (which is likely an nkIdent) has to be restored: if result == nil: + # XXX: hmm, what kind of symbols will end up here? + # do we really need to try the overload resolution? n.sons[0] = prc nOrig.sons[0] = prc + n.flags.incl nfExprCall result = semOverloadedCallAnalyseEffects(c, n, nOrig, flags) - if result == nil: - if c.inCompilesContext > 0 or gErrorCounter == 0: - LocalError(n.info, errExprXCannotBeCalled, - renderTree(n, {renderNoComments})) - return errorNode(c, n) #result = afterCallActions(c, result, nOrig, flags) fixAbstractType(c, result) analyseIfAddressTakenInCall(c, result) diff --git a/tests/reject/tnoop.nim b/tests/reject/tnoop.nim index 2d320c8499..c79403e113 100644 --- a/tests/reject/tnoop.nim +++ b/tests/reject/tnoop.nim @@ -3,11 +3,10 @@ discard """ line: 11 errormsg: "expression \'a()\' cannot be called" """ -# Tests the new check in the semantic pass - -var - a: int - -a() #ERROR_MSG expression 'a()' cannot be called +# Tests the new check in the semantic pass +var + a: int + +a() #ERROR_MSG expression 'a()' cannot be called