fixes #1713
This commit is contained in:
parent
52ab2f86a8
commit
4180f59b27
5 changed files with 32 additions and 11 deletions
|
|
@ -938,7 +938,7 @@ const
|
||||||
genericParamsPos* = 2
|
genericParamsPos* = 2
|
||||||
paramsPos* = 3
|
paramsPos* = 3
|
||||||
pragmasPos* = 4
|
pragmasPos* = 4
|
||||||
optimizedCodePos* = 5 # will be used for exception tracking
|
miscPos* = 5 # used for undocumented and hacky stuff
|
||||||
bodyPos* = 6 # position of body; use rodread.getBody() instead!
|
bodyPos* = 6 # position of body; use rodread.getBody() instead!
|
||||||
resultPos* = 7
|
resultPos* = 7
|
||||||
dispatcherPos* = 8 # caution: if method has no 'result' it can be position 7!
|
dispatcherPos* = 8 # caution: if method has no 'result' it can be position 7!
|
||||||
|
|
|
||||||
|
|
@ -712,6 +712,10 @@ proc gproc(g: var TSrcGen, n: PNode) =
|
||||||
gpattern(g, n.sons[patternPos])
|
gpattern(g, n.sons[patternPos])
|
||||||
let oldCheckAnon = g.checkAnon
|
let oldCheckAnon = g.checkAnon
|
||||||
g.checkAnon = true
|
g.checkAnon = true
|
||||||
|
if renderNoBody in g.flags and n[miscPos].kind != nkEmpty and
|
||||||
|
n[miscPos][1].kind != nkEmpty:
|
||||||
|
gsub(g, n[miscPos][1])
|
||||||
|
else:
|
||||||
gsub(g, n.sons[genericParamsPos])
|
gsub(g, n.sons[genericParamsPos])
|
||||||
g.checkAnon = oldCheckAnon
|
g.checkAnon = oldCheckAnon
|
||||||
gsub(g, n.sons[paramsPos])
|
gsub(g, n.sons[paramsPos])
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,10 @@ proc notFoundError*(c: PContext, n: PNode, errors: CandidateErrors) =
|
||||||
add(result, ')')
|
add(result, ')')
|
||||||
var candidates = ""
|
var candidates = ""
|
||||||
for err in errors:
|
for err in errors:
|
||||||
|
if err.kind in routineKinds and err.ast != nil:
|
||||||
|
add(candidates, renderTree(err.ast,
|
||||||
|
{renderNoBody, renderNoComments,renderNoPragmas}))
|
||||||
|
else:
|
||||||
add(candidates, err.getProcHeader(prefer))
|
add(candidates, err.getProcHeader(prefer))
|
||||||
add(candidates, "\n")
|
add(candidates, "\n")
|
||||||
if candidates != "":
|
if candidates != "":
|
||||||
|
|
|
||||||
|
|
@ -929,6 +929,17 @@ proc semProcAnnotation(c: PContext, prc: PNode;
|
||||||
pragma(c, result[namePos].sym, result[pragmasPos], validPragmas)
|
pragma(c, result[namePos].sym, result[pragmasPos], validPragmas)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
proc setGenericParamsMisc(c: PContext; n: PNode): PNode =
|
||||||
|
let orig = n.sons[genericParamsPos]
|
||||||
|
# we keep the original params around for better error messages, see
|
||||||
|
# issue https://github.com/nim-lang/Nim/issues/1713
|
||||||
|
result = semGenericParamList(c, orig)
|
||||||
|
if n.sons[miscPos].kind == nkEmpty:
|
||||||
|
n.sons[miscPos] = newTree(nkBracket, ast.emptyNode, orig)
|
||||||
|
else:
|
||||||
|
n.sons[miscPos].sons[1] = orig
|
||||||
|
n.sons[genericParamsPos] = result
|
||||||
|
|
||||||
proc semLambda(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
proc semLambda(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
# XXX semProcAux should be good enough for this now, we will eventually
|
# XXX semProcAux should be good enough for this now, we will eventually
|
||||||
# remove semLambda
|
# remove semLambda
|
||||||
|
|
@ -947,8 +958,7 @@ proc semLambda(c: PContext, n: PNode, flags: TExprFlags): PNode =
|
||||||
openScope(c)
|
openScope(c)
|
||||||
var gp: PNode
|
var gp: PNode
|
||||||
if n.sons[genericParamsPos].kind != nkEmpty:
|
if n.sons[genericParamsPos].kind != nkEmpty:
|
||||||
n.sons[genericParamsPos] = semGenericParamList(c, n.sons[genericParamsPos])
|
gp = setGenericParamsMisc(c, n)
|
||||||
gp = n.sons[genericParamsPos]
|
|
||||||
else:
|
else:
|
||||||
gp = newNodeI(nkGenericParams, n.info)
|
gp = newNodeI(nkGenericParams, n.info)
|
||||||
|
|
||||||
|
|
@ -1170,8 +1180,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||||
openScope(c)
|
openScope(c)
|
||||||
var gp: PNode
|
var gp: PNode
|
||||||
if n.sons[genericParamsPos].kind != nkEmpty:
|
if n.sons[genericParamsPos].kind != nkEmpty:
|
||||||
n.sons[genericParamsPos] = semGenericParamList(c, n.sons[genericParamsPos])
|
gp = setGenericParamsMisc(c, n)
|
||||||
gp = n.sons[genericParamsPos]
|
|
||||||
else:
|
else:
|
||||||
gp = newNodeI(nkGenericParams, n.info)
|
gp = newNodeI(nkGenericParams, n.info)
|
||||||
# process parameters:
|
# process parameters:
|
||||||
|
|
|
||||||
|
|
@ -1887,8 +1887,8 @@ proc optimizeJumps(c: PCtx; start: int) =
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc genProc(c: PCtx; s: PSym): int =
|
proc genProc(c: PCtx; s: PSym): int =
|
||||||
let x = s.ast.sons[optimizedCodePos]
|
var x = s.ast.sons[miscPos]
|
||||||
if x.kind == nkEmpty:
|
if x.kind == nkEmpty or x[0].kind == nkEmpty:
|
||||||
#if s.name.s == "outterMacro" or s.name.s == "innerProc":
|
#if s.name.s == "outterMacro" or s.name.s == "innerProc":
|
||||||
# echo "GENERATING CODE FOR ", s.name.s
|
# echo "GENERATING CODE FOR ", s.name.s
|
||||||
let last = c.code.len-1
|
let last = c.code.len-1
|
||||||
|
|
@ -1899,7 +1899,11 @@ proc genProc(c: PCtx; s: PSym): int =
|
||||||
c.debug.setLen(last)
|
c.debug.setLen(last)
|
||||||
#c.removeLastEof
|
#c.removeLastEof
|
||||||
result = c.code.len+1 # skip the jump instruction
|
result = c.code.len+1 # skip the jump instruction
|
||||||
s.ast.sons[optimizedCodePos] = newIntNode(nkIntLit, result)
|
if x.kind == nkEmpty:
|
||||||
|
x = newTree(nkBracket, newIntNode(nkIntLit, result), ast.emptyNode)
|
||||||
|
else:
|
||||||
|
x.sons[0] = newIntNode(nkIntLit, result)
|
||||||
|
s.ast.sons[miscPos] = x
|
||||||
# thanks to the jmp we can add top level statements easily and also nest
|
# thanks to the jmp we can add top level statements easily and also nest
|
||||||
# procs easily:
|
# procs easily:
|
||||||
let body = s.getBody
|
let body = s.getBody
|
||||||
|
|
@ -1934,4 +1938,4 @@ proc genProc(c: PCtx; s: PSym): int =
|
||||||
c.prc = oldPrc
|
c.prc = oldPrc
|
||||||
else:
|
else:
|
||||||
c.prc.maxSlots = s.offset
|
c.prc.maxSlots = s.offset
|
||||||
result = x.intVal.int
|
result = x[0].intVal.int
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue