From d34f95d1940d31d42bf0ce3c16c5366e41e668aa Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Sun, 10 Mar 2013 19:49:02 -0500 Subject: nestedTryStmts removed It makes tests fail and they work fine without. Given my ignorance of the exact workings, I can only rely on the tests. --- tests/run/tfinally.nim | 8 +++++--- tests/run/tfinally2.nim | 17 ++++++++++------- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/run/tfinally.nim b/tests/run/tfinally.nim index 29313c3fd..2522dd0e4 100755 --- a/tests/run/tfinally.nim +++ b/tests/run/tfinally.nim @@ -1,6 +1,8 @@ discard """ file: "tfinally.nim" - output: "came here 3" + output: "came +here +3" """ # Test return in try statement: @@ -9,10 +11,10 @@ proc main: int = try: return 1 finally: - stdout.write("came ") + echo("came") return 2 finally: - stdout.write("here ") + echo("here ") return 3 echo main() #OUT came here 3 diff --git a/tests/run/tfinally2.nim b/tests/run/tfinally2.nim index 3ed212a7c..af94aee5b 100755 --- a/tests/run/tfinally2.nim +++ b/tests/run/tfinally2.nim @@ -1,6 +1,9 @@ discard """ file: "tfinally2.nim" - output: "ABCD" + output: "A +B +C +D" """ # Test break in try statement: @@ -11,15 +14,15 @@ proc main: int = try: break AB finally: - stdout.write("A") - stdout.write("skipped") + echo("A") + echo("skipped") finally: block B: - stdout.write("B") - stdout.write("skipped") - stdout.write("C") + echo("B") + echo("skipped") + echo("C") finally: - stdout.writeln("D") + echo("D") discard main() #OUT ABCD -- cgit 1.4.1-2-gfad0 From 78b27ed7fa121d2cb032fa1b74ae434034bf8e23 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 11 Mar 2013 08:42:35 +0100 Subject: bugfix: 'indexOf' for tuple fields works --- compiler/semfold.nim | 11 +++++++++-- compiler/semgnrc.nim | 5 ----- tests/run/tfieldindex.nim | 21 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 7 deletions(-) create mode 100644 tests/run/tfieldindex.nim (limited to 'tests') diff --git a/compiler/semfold.nim b/compiler/semfold.nim index e26700e27..d304ddd3c 100755 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -490,7 +490,7 @@ proc getArrayConstr(m: PSym, n: PNode): PNode = proc foldArrayAccess(m: PSym, n: PNode): PNode = var x = getConstExpr(m, n.sons[0]) - if x == nil: return + if x == nil or x.typ.skipTypes({tyGenericInst}).kind == tyTypeDesc: return var y = getConstExpr(m, n.sons[1]) if y == nil: return @@ -541,7 +541,12 @@ proc foldConStrStr(m: PSym, n: PNode): PNode = let a = getConstExpr(m, n.sons[i]) if a == nil: return nil result.strVal.add(getStrOrChar(a)) - + +proc newSymNodeTypeDesc*(s: PSym; info: TLineInfo): PNode = + result = newSymNode(s, info) + result.typ = newType(tyTypeDesc, s.owner) + result.typ.addSonSkipIntLit(s.typ) + proc getConstExpr(m: PSym, n: PNode): PNode = result = nil case n.kind @@ -569,6 +574,8 @@ proc getConstExpr(m: PSym, n: PNode): PNode = if sfFakeConst notin s.flags: result = copyTree(s.ast) elif s.kind in {skProc, skMethod}: # BUGFIX result = n + elif s.kind in {skType, skGenericParam}: + result = newSymNodeTypeDesc(s, n.info) of nkCharLit..nkNilLit: result = copyNode(n) of nkIfExpr: diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index 2e1eccda2..8c3cef027 100755 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -31,11 +31,6 @@ proc getIdentNode(n: PNode): PNode = illFormedAst(n) result = n -proc newSymNodeTypeDesc(s: PSym; info: TLineInfo): PNode = - result = newSymNode(s, info) - result.typ = newType(tyTypeDesc, s.owner) - result.typ.addSonSkipIntLit(s.typ) - proc semGenericStmt(c: PContext, n: PNode, flags: TSemGenericFlags, ctx: var TIntSet): PNode proc semGenericStmtScope(c: PContext, n: PNode, diff --git a/tests/run/tfieldindex.nim b/tests/run/tfieldindex.nim new file mode 100644 index 000000000..3ffa65e58 --- /dev/null +++ b/tests/run/tfieldindex.nim @@ -0,0 +1,21 @@ +discard """ + output: "1" +""" + +type + TMyTuple = tuple[a, b: int] + +proc indexOf*(t: typedesc, name: string): int {.compiletime.} = + ## takes a tuple and looks for the field by name. + ## returs index of that field. + var + d: t + i = 0 + for n, x in fieldPairs(d): + if n == name: return i + i.inc + raise newException(EInvalidValue, "No field " & name & " in type " & + astToStr(t)) + +echo TMyTuple.indexOf("b") + -- cgit 1.4.1-2-gfad0 From 129fcb327fb1900af0d9e55a668d7808344d29f3 Mon Sep 17 00:00:00 2001 From: Simon Hafner Date: Sat, 16 Mar 2013 07:21:31 -0500 Subject: used correct syntax for multiline results in tests And also modified the runner to actually run them in JS. --- tests/run/tfinally.nim | 4 ++-- tests/run/tfinally2.nim | 4 ++-- tests/specials.nim | 8 ++------ 3 files changed, 6 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/run/tfinally.nim b/tests/run/tfinally.nim index 2522dd0e4..273aac72b 100755 --- a/tests/run/tfinally.nim +++ b/tests/run/tfinally.nim @@ -1,8 +1,8 @@ discard """ file: "tfinally.nim" - output: "came + output: '''came here -3" +3''' """ # Test return in try statement: diff --git a/tests/run/tfinally2.nim b/tests/run/tfinally2.nim index af94aee5b..e1e8d4c7e 100755 --- a/tests/run/tfinally2.nim +++ b/tests/run/tfinally2.nim @@ -1,9 +1,9 @@ discard """ file: "tfinally2.nim" - output: "A + output: '''A B C -D" +D''' """ # Test break in try statement: diff --git a/tests/specials.nim b/tests/specials.nim index 1818497a4..b5c49ec3c 100644 --- a/tests/specials.nim +++ b/tests/specials.nim @@ -176,14 +176,10 @@ proc runJsTests(r: var TResults, options: string) = runSingleTest(r, filename, options & " -d:nodejs", targetJS) runSingleTest(r, filename, options & " -d:nodejs -d:release", targetJS) - # texceptions, texcpt1, texcsub, tfinally, tfinally2, - # tfinally3 for t in os.walkFiles("tests/js/t*.nim"): test(t) - test "tests/run/tactiontable" - test "tests/run/tmultim1" - test "tests/run/tmultim3" - test "tests/run/tmultim4" + for testfile in ["texceptions", "texcpt1", "texcsub", "tfinally", "tfinally2", "tfinally3", "tactiontable", "tmultim1", "tmultim3", "tmultim4"]: + test "tests/run/" & testfile & ".nim" # ------------------------- register special tests here ----------------------- proc runSpecialTests(r: var TResults, options: string) = -- cgit 1.4.1-2-gfad0