diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2018-09-24 12:14:43 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-09-24 16:00:57 +0200 |
commit | 9364369c1f346b9b328274f495267488bfe30b63 (patch) | |
tree | 6c7ee33dcdac9f77b45280f364f8940a175a26de | |
parent | c38a608c9099e987a8be0149b5190a4fc2d5fb33 (diff) | |
download | Nim-9364369c1f346b9b328274f495267488bfe30b63.tar.gz |
make tests green again
-rw-r--r-- | compiler/destroyer.nim | 8 | ||||
-rw-r--r-- | compiler/passes.nim | 6 | ||||
-rw-r--r-- | compiler/sem.nim | 12 | ||||
-rw-r--r-- | compiler/semasgn.nim | 3 | ||||
-rw-r--r-- | tests/errmsgs/t5167_5.nim | 10 | ||||
-rw-r--r-- | tests/pragmas/tnoreturn.nim | 4 | ||||
-rw-r--r-- | tests/pragmas/treorder.nim | 6 | ||||
-rw-r--r-- | tests/trmacros/tor.nim | 4 | ||||
-rw-r--r-- | tests/types/t6969.nim | 6 |
9 files changed, 34 insertions, 25 deletions
diff --git a/compiler/destroyer.nim b/compiler/destroyer.nim index bd735560a..ff5494ad8 100644 --- a/compiler/destroyer.nim +++ b/compiler/destroyer.nim @@ -291,21 +291,21 @@ proc genMagicCall(n: PNode; c: var Con; magicname: string; m: TMagic): PNode = proc moveOrCopy(dest, ri: PNode; c: var Con): PNode = if ri.kind in constrExprs: - result = genSink(c, ri.typ, dest) + result = genSink(c, dest.typ, dest) # watch out and no not transform 'ri' twice if it's a call: let ri2 = copyNode(ri) recurse(ri, ri2) result.add ri2 elif ri.kind == nkSym and isHarmlessVar(ri.sym, c): # Rule 3: `=sink`(x, z); wasMoved(z) - var snk = genSink(c, ri.typ, dest) + var snk = genSink(c, dest.typ, dest) snk.add p(ri, c) result = newTree(nkStmtList, snk, genMagicCall(ri, c, "wasMoved", mWasMoved)) elif ri.kind == nkSym and isSinkParam(ri.sym): - result = genSink(c, ri.typ, dest) + result = genSink(c, dest.typ, dest) result.add destructiveMoveSink(ri, c) else: - result = genCopy(c, ri.typ, dest) + result = genCopy(c, dest.typ, dest) result.add p(ri, c) proc passCopyToSink(n: PNode; c: var Con): PNode = diff --git a/compiler/passes.nim b/compiler/passes.nim index 645c1444b..718b42c2a 100644 --- a/compiler/passes.nim +++ b/compiler/passes.nim @@ -127,7 +127,8 @@ proc processImplicits(conf: ConfigRef; implicits: seq[string], nodeKind: TNodeKi const imperativeCode = {low(TNodeKind)..high(TNodeKind)} - {nkTemplateDef, nkProcDef, nkMethodDef, - nkMacroDef, nkConverterDef, nkIteratorDef, nkFuncDef} + nkMacroDef, nkConverterDef, nkIteratorDef, nkFuncDef, nkPragma, + nkExportStmt, nkExportExceptStmt, nkFromStmt, nkImportStmt, nkImportExceptStmt} proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream): bool {.discardable.} = if graph.stopCompile(): return true @@ -206,10 +207,13 @@ proc processModule*(graph: ModuleGraph; module: PSym, stream: PLLStream): bool { rest = n break sl.add n + #echo "-----\n", sl if not processTopLevelStmt(sl, a): break if rest != nil: + #echo "-----\n", rest if not processTopLevelStmt(rest, a): break else: + #echo "----- single\n", n if not processTopLevelStmt(n, a): break closeParsers(p) if s.kind != llsStdIn: break diff --git a/compiler/sem.nim b/compiler/sem.nim index 5e5205c20..dbc174d50 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -542,12 +542,20 @@ proc isImportSystemStmt(g: ModuleGraph; n: PNode): bool = return true else: discard +proc isEmptyTree(n: PNode): bool = + case n.kind + of nkStmtList: + for it in n: + if not isEmptyTree(it): return false + result = true + of nkEmpty, nkCommentStmt: result = true + else: result = false + proc semStmtAndGenerateGenerics(c: PContext, n: PNode): PNode = if n.kind == nkDefer: localError(c.config, n.info, "defer statement not supported at top level") if c.topStmts == 0 and not isImportSystemStmt(c.graph, n): - if sfSystemModule notin c.module.flags and - n.kind notin {nkEmpty, nkCommentStmt}: + if sfSystemModule notin c.module.flags and not isEmptyTree(n): c.importTable.addSym c.graph.systemModule # import the "System" identifier importAllSymbols(c, c.graph.systemModule) inc c.topStmts diff --git a/compiler/semasgn.nim b/compiler/semasgn.nim index 8b2e20efc..f781972a5 100644 --- a/compiler/semasgn.nim +++ b/compiler/semasgn.nim @@ -216,7 +216,8 @@ proc liftBodyAux(c: var TLiftCtx; t: PType; body, x, y: PNode) = if c.c.config.selectedGC == gcDestructors: discard considerOverloadedOp(c, t, body, x, y) elif tfHasAsgn in t.flags: - body.add newSeqCall(c.c, x, y) + if c.kind != attachedDestructor: + body.add newSeqCall(c.c, x, y) let i = declareCounter(c, body, firstOrd(c.c.config, t)) let whileLoop = genWhileLoop(c, i, x) let elemType = t.lastSon diff --git a/tests/errmsgs/t5167_5.nim b/tests/errmsgs/t5167_5.nim index ab02f29f6..ccd9cc0a5 100644 --- a/tests/errmsgs/t5167_5.nim +++ b/tests/errmsgs/t5167_5.nim @@ -1,18 +1,18 @@ discard """ cmd: "nim check $file" -errormsg: "'m' has unspecified generic parameters" +errormsg: "'t' has unspecified generic parameters" nimout: ''' t5167_5.nim(20, 9) Error: 't' has unspecified generic parameters -t5167_5.nim(21, 5) Error: 't' has unspecified generic parameters -t5167_5.nim(23, 9) Error: 'm' has unspecified generic parameters -t5167_5.nim(24, 5) Error: 'm' has unspecified generic parameters ''' """ + + + template t[B]() = echo "foo1" -macro m[T]: stmt = nil +macro m[T]: untyped = nil proc bar(x: proc (x: int)) = echo "bar" diff --git a/tests/pragmas/tnoreturn.nim b/tests/pragmas/tnoreturn.nim index bb59b1c71..50b427d71 100644 --- a/tests/pragmas/tnoreturn.nim +++ b/tests/pragmas/tnoreturn.nim @@ -9,8 +9,8 @@ proc noret1*(i: int) {.noreturn.} = proc noret2*(i: int): void {.noreturn.} = echo i -noret1(1) -noret2(2) +if true: noret1(1) +if true: noret2(2) var p {.used.}: proc(i: int): int doAssert(not compiles( diff --git a/tests/pragmas/treorder.nim b/tests/pragmas/treorder.nim index 659a6f644..09a98ef6a 100644 --- a/tests/pragmas/treorder.nim +++ b/tests/pragmas/treorder.nim @@ -14,10 +14,10 @@ echo callWithFoo(0) echo(CA+CD) echo useTypes(TA(x:TB(x:1)), 2) second(0) - + template callWithFoo(arg: untyped): untyped = foo(arg) - + proc first(i: int): void proc second(i: int): void = @@ -35,7 +35,7 @@ type type TCyclicA = ref object x: TDoubleCyclic - + type TCyclicB = ref object x: TDoubleCyclic diff --git a/tests/trmacros/tor.nim b/tests/trmacros/tor.nim index d698e928d..087dc0d68 100644 --- a/tests/trmacros/tor.nim +++ b/tests/trmacros/tor.nim @@ -1,11 +1,11 @@ discard """ - output: '''3030 + output: '''0 true 3''' """ template arithOps: untyped = (`+` | `-` | `*`) -template testOr{ (arithOps{f})(a, b) }(a, b, f: untyped): untyped = f(a+1, b) +template testOr{ (arithOps{f})(a, b) }(a, b, f: untyped): untyped = f(a mod 10, b) let xx = 10 echo 10*xx diff --git a/tests/types/t6969.nim b/tests/types/t6969.nim index d6ce5e62a..14a8481cf 100644 --- a/tests/types/t6969.nim +++ b/tests/types/t6969.nim @@ -3,8 +3,4 @@ errormsg: "invalid type: 'object' for var" line: 6 """ -var a: object a: int -# or -var b: ref object a: int -# or -var c: ptr object a: int \ No newline at end of file +var a: object |