This commit is contained in:
Andreas Rumpf 2018-01-08 18:02:38 +01:00
commit ceb8ba4957

View file

@ -1865,17 +1865,16 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode =
result = magicsAfterOverloadResolution(c, result, flags) result = magicsAfterOverloadResolution(c, result, flags)
of mRunnableExamples: of mRunnableExamples:
if gCmd == cmdDoc and n.len >= 2 and n.lastSon.kind == nkStmtList: if gCmd == cmdDoc and n.len >= 2 and n.lastSon.kind == nkStmtList:
if n.sons[0].kind == nkIdent: if sfMainModule in c.module.flags:
if sfMainModule in c.module.flags: let inp = toFullPath(c.module.info)
let inp = toFullPath(c.module.info) if c.runnableExamples == nil:
if c.runnableExamples == nil: c.runnableExamples = newTree(nkStmtList,
c.runnableExamples = newTree(nkStmtList, newTree(nkImportStmt, newStrNode(nkStrLit, expandFilename(inp))))
newTree(nkImportStmt, newStrNode(nkStrLit, expandFilename(inp)))) let imports = newTree(nkStmtList)
let imports = newTree(nkStmtList) extractImports(n.lastSon, imports)
extractImports(n.lastSon, imports) for imp in imports: c.runnableExamples.add imp
for imp in imports: c.runnableExamples.add imp c.runnableExamples.add newTree(nkBlockStmt, emptyNode, copyTree n.lastSon)
c.runnableExamples.add newTree(nkBlockStmt, emptyNode, copyTree n.lastSon) result = setMs(n, s)
result = setMs(n, s)
else: else:
result = emptyNode result = emptyNode
else: else: