Merge pull request #9911 from nc-x/fixes-#9627

`include` now accepts collective arguments
This commit is contained in:
Andreas Rumpf 2018-12-09 13:47:45 +01:00 • committed by GitHub
commit 606b43ba11
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 7 deletions

View file

@ -1843,17 +1843,33 @@ proc semMacroDef(c: PContext, n: PNode): PNode =
if n.sons[bodyPos].kind == nkEmpty: if n.sons[bodyPos].kind == nkEmpty:
localError(c.config, n.info, errImplOfXexpected % s.name.s) localError(c.config, n.info, errImplOfXexpected % s.name.s)
proc incMod(c: PContext, n: PNode, it: PNode, includeStmtResult: PNode) =
var f = checkModuleName(c.config, it)
if f != InvalidFileIDX:
if containsOrIncl(c.includedFiles, f.int):
localError(c.config, n.info, errRecursiveDependencyX % toFilename(c.config, f))
else:
addSon(includeStmtResult, semStmt(c, c.graph.includeFileCallback(c.graph, c.module, f), {}))
excl(c.includedFiles, f.int)
proc evalInclude(c: PContext, n: PNode): PNode = proc evalInclude(c: PContext, n: PNode): PNode =
result = newNodeI(nkStmtList, n.info) result = newNodeI(nkStmtList, n.info)
addSon(result, n) addSon(result, n)
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
var f = checkModuleName(c.config, n.sons[i]) var imp: PNode
if f != InvalidFileIDX: let it = n.sons[i]
if containsOrIncl(c.includedFiles, f.int): if it.kind == nkInfix and it.len == 3 and it[2].kind == nkBracket:
localError(c.config, n.info, errRecursiveDependencyX % toFilename(c.config, f)) let sep = it[0]
else: let dir = it[1]
addSon(result, semStmt(c, c.graph.includeFileCallback(c.graph, c.module, f), {})) imp = newNodeI(nkInfix, it.info)
excl(c.includedFiles, f.int) imp.add sep
imp.add dir
imp.add sep # dummy entry, replaced in the loop
for x in it[2]:
imp.sons[2] = x
incMod(c, n, imp, result)
else:
incMod(c, n, it, result)
proc setLine(n: PNode, info: TLineInfo) = proc setLine(n: PNode, info: TLineInfo) =
for i in 0 ..< safeLen(n): setLine(n.sons[i], info) for i in 0 ..< safeLen(n): setLine(n.sons[i], info)

View file

@ -0,0 +1 @@
var a = 10

View file

@ -0,0 +1 @@
var b = 9

7
tests/modules/t9627.nim Normal file
View file

@ -0,0 +1,7 @@
discard """
output: "109"
"""
include m9627 / [a, b]
echo a, b