diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2017-09-15 09:27:51 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2017-09-15 09:27:51 +0200 |
commit | 39f0195ebf30cc9f4b96953423298d7a2130eac8 (patch) | |
tree | bb4daf580c239b59d232e186814b69fc642ce6d5 /tests | |
parent | bc738d63a728ee6030cc224c8808990a6f641feb (diff) | |
parent | 2ef65d5cdf3d65cbfab4c39796ddb4e70e9ebb37 (diff) | |
download | Nim-39f0195ebf30cc9f4b96953423298d7a2130eac8.tar.gz |
Merge branch 'devel' into araq
Diffstat (limited to 'tests')
202 files changed, 1554 insertions, 794 deletions
diff --git a/tests/alias/talias.nim b/tests/alias/talias.nim index 810ea2095..a8f1b0dd0 100644 --- a/tests/alias/talias.nim +++ b/tests/alias/talias.nim @@ -8,17 +8,17 @@ proc isPartOf*[S, T](a: S, b: T): TAnalysisResult {. magic: "IsPartOf", noSideEffect.} ## not yet exported properly. -template compileTimeAssert(cond: expr) = +template compileTimeAssert(cond) = when not cond: {.compile: "is false: " & astToStr(cond).} -template `<|` (a, b: expr) = +template `<|` (a, b) = compileTimeAssert isPartOf(a, b) == arYes -template `!<|` (a, b: expr) = +template `!<|` (a, b) = compileTimeAssert isPartOf(a, b) == arNo -template `?<|` (a, b: expr) = +template `?<|` (a, b) = compileTimeAssert isPartOf(a, b) == arMaybe type diff --git a/tests/arithm/tshr.nim b/tests/arithm/tshr.nim index e9b72f1df..4ba34aed9 100644 --- a/tests/arithm/tshr.nim +++ b/tests/arithm/tshr.nim @@ -3,18 +3,18 @@ discard """ """ proc T() = - let VI = -8 - let VI64 = -8'i64 - let VI32 = -8'i32 - let VI16 = -8'i16 - let VI8 = -8'i8 - doAssert( (VI shr 1) == 9223372036854775804) - doAssert( (VI64 shr 1) == 9223372036854775804) - doAssert( (VI32 shr 1) == 2147483644) - doAssert( (VI16 shr 1) == 32764) - doAssert( (VI8 shr 1) == 124) + # let VI = -8 + let VI64 = -8'i64 + let VI32 = -8'i32 + let VI16 = -8'i16 + let VI8 = -8'i8 + # doAssert( (VI shr 1) == 9_223_372_036_854_775_804, "Actual: " & $(VI shr 1)) + doAssert( (VI64 shr 1) == 9_223_372_036_854_775_804, "Actual: " & $(VI64 shr 1)) + doAssert( (VI32 shr 1) == 2_147_483_644, "Actual: " & $(VI32 shr 1)) + doAssert( (VI16 shr 1) == 32_764, "Actual: " & $(VI16 shr 1)) + doAssert( (VI8 shr 1) == 124, "Actual: " & $(VI8 shr 1)) T() static: - T() + T() diff --git a/tests/array/tunchecked.nim b/tests/array/tunchecked.nim new file mode 100644 index 000000000..f5ac3642d --- /dev/null +++ b/tests/array/tunchecked.nim @@ -0,0 +1,5 @@ +{.boundchecks: on.} +type Unchecked {.unchecked.} = array[0, char] + +var x = cast[ptr Unchecked](alloc(100)) +x[5] = 'x' diff --git a/tests/assert/tuserassert.nim b/tests/assert/tuserassert.nim index 7bb0a7fc0..274c78921 100644 --- a/tests/assert/tuserassert.nim +++ b/tests/assert/tuserassert.nim @@ -2,7 +2,7 @@ discard """ output: "x == 45ugh" """ -template myAssert(cond: expr) = +template myAssert(cond: untyped) = when 3 <= 3: let c = cond.astToStr if not cond: diff --git a/tests/async/tasync_gcsafe.nim b/tests/async/tasync_gcsafe.nim new file mode 100644 index 000000000..89df6456a --- /dev/null +++ b/tests/async/tasync_gcsafe.nim @@ -0,0 +1,36 @@ +discard """ + cmd: "nim c --threads:on $file" + output: ''' +1 +2 +3 +''' +""" + +assert compileOption("threads"), "this test will not do anything useful without --threads:on" + +import asyncdispatch + +var globalDummy: ref int +proc gcUnsafeProc() = + if not globalDummy.isNil: + echo globalDummy[] + echo "1" + +proc gcSafeAsyncProcWithNoAnnotation() {.async.} = + echo "2" + +proc gcSafeAsyncProcWithAnnotation() {.gcsafe, async.} = + echo "3" + +proc gcUnsafeAsyncProc() {.async.} = + # We should be able to call gcUnsafe + gcUnsafeProc() + + # We should be able to call async implicitly gcsafe + await gcSafeAsyncProcWithNoAnnotation() + + # We should be able to call async explicitly gcsafe + await gcSafeAsyncProcWithAnnotation() + +waitFor gcUnsafeAsyncProc() diff --git a/tests/async/tasync_gcunsafe.nim b/tests/async/tasync_gcunsafe.nim new file mode 100644 index 000000000..f4e2cdcf2 --- /dev/null +++ b/tests/async/tasync_gcunsafe.nim @@ -0,0 +1,30 @@ +discard """ + cmd: "nim c --threads:on $file" + file: "asyncmacro.nim" + errormsg: "'anotherGCSafeAsyncProcIter' is not GC-safe as it calls 'asyncGCUnsafeProc'" +""" + +assert compileOption("threads"), "this test will not do anything useful without --threads:on" + +import asyncdispatch + +var globalDummy: ref int +proc gcUnsafeProc() = + if not globalDummy.isNil: + echo globalDummy[] + +proc asyncExplicitlyGCSafeProc() {.gcsafe, async.} = + echo "hi" + +proc asyncImplicitlyGCSafeProc() {.async.} = + echo "hi" + +proc asyncGCUnsafeProc() {.async.} = + gcUnsafeProc() + +proc anotherGCSafeAsyncProc() {.async, gcsafe.} = + # We should be able to call other gcsafe procs + await asyncExplicitlyGCSafeProc() + await asyncImplicitlyGCSafeProc() + # But we can't call gcunsafe procs + await asyncGCUnsafeProc() diff --git a/tests/async/tasyncrecursion.nim b/tests/async/tasyncrecursion.nim index 54482edab..1aeebe9b4 100644 --- a/tests/async/tasyncrecursion.nim +++ b/tests/async/tasyncrecursion.nim @@ -17,5 +17,6 @@ proc asyncRecursionTest*(): Future[int] {.async.} = inc(i) when isMainModule: + setGlobalDispatcher(newDispatcher()) var i = waitFor asyncRecursionTest() echo i diff --git a/tests/async/tcallbacks.nim b/tests/async/tcallbacks.nim new file mode 100644 index 000000000..8c08032cd --- /dev/null +++ b/tests/async/tcallbacks.nim @@ -0,0 +1,20 @@ +discard """ + exitcode: 0 + output: '''3 +2 +1 +5 +''' +""" +import asyncfutures + +let f1: Future[int] = newFuture[int]() +f1.addCallback(proc() = echo 1) +f1.addCallback(proc() = echo 2) +f1.addCallback(proc() = echo 3) +f1.complete(10) + +let f2: Future[int] = newFuture[int]() +f2.addCallback(proc() = echo 4) +f2.callback = proc() = echo 5 +f2.complete(10) diff --git a/tests/bind/mbind3.nim b/tests/bind/mbind3.nim index aad080223..1a7d3b63b 100644 --- a/tests/bind/mbind3.nim +++ b/tests/bind/mbind3.nim @@ -2,7 +2,7 @@ var lastId = 0 -template genId*: expr = +template genId*: int = bind lastId inc(lastId) lastId diff --git a/tests/bind/tbind1.nim b/tests/bind/tbind1.nim index 2665d0b5c..9b13a7d11 100644 --- a/tests/bind/tbind1.nim +++ b/tests/bind/tbind1.nim @@ -6,7 +6,7 @@ discard """ proc p1(x: int8, y: int): int = return x + y -template tempBind(x, y: expr): expr = +template tempBind(x, y): untyped = bind p1 p1(x, y) diff --git a/tests/bind/tbind2.nim b/tests/bind/tbind2.nim index 0e0cbd788..799b14381 100644 --- a/tests/bind/tbind2.nim +++ b/tests/bind/tbind2.nim @@ -8,7 +8,7 @@ discard """ proc p1(x: int8, y: int): int = return x + y proc p1(x: int, y: int8): int = return x - y -template tempBind(x, y: expr): expr = +template tempBind(x, y): untyped = (bind p1(x, y)) #ERROR_MSG ambiguous call echo tempBind(1'i8, 2'i8) diff --git a/tests/ccgbugs/t6279.nim b/tests/ccgbugs/t6279.nim new file mode 100644 index 000000000..37345d807 --- /dev/null +++ b/tests/ccgbugs/t6279.nim @@ -0,0 +1,9 @@ +discard """ +cmd: "nim c -r -d:fulldebug -d:smokeCycles --gc:refc $file" +output: '''@[a]''' +""" + +# bug #6279 +var foo = newSeq[tuple[a: seq[string], b: seq[string]]]() +foo.add((@["a"], @["b"])) +echo foo[0].a # Crashes on this line diff --git a/tests/ccgbugs/taddhigh.nim b/tests/ccgbugs/taddhigh.nim index d6ac8f650..549eb8caa 100644 --- a/tests/ccgbugs/taddhigh.nim +++ b/tests/ccgbugs/taddhigh.nim @@ -1,5 +1,5 @@ discard """ - output: '''@[5, 5, 5]''' + output: '''@[5, 5, 5, 5, 5]''' """ # bug #1832 @@ -13,4 +13,7 @@ s.add x # Causes the 0 to appear: s.add s[s.high] +s.add s[s.len-1] +s.add s[s.xlen-1] + echo s # @[5, 5, 0] diff --git a/tests/ccgbugs/tnocodegen_for_compiletime.nim b/tests/ccgbugs/tnocodegen_for_compiletime.nim index a88ba4b32..b44e9f8c9 100644 --- a/tests/ccgbugs/tnocodegen_for_compiletime.nim +++ b/tests/ccgbugs/tnocodegen_for_compiletime.nim @@ -1,7 +1,7 @@ # bug #1679 import macros, tables, hashes proc hash(v: NimNode): Hash = 4 # performance is for suckers -macro test(body: stmt): stmt {.immediate.} = +macro test(body: untyped): typed = var a = initCountTable[NimNode]() a.inc(body) diff --git a/tests/ccgbugs/tuple_canon.nim b/tests/ccgbugs/tuple_canon.nim index a607f9cab..45fed8eee 100644 --- a/tests/ccgbugs/tuple_canon.nim +++ b/tests/ccgbugs/tuple_canon.nim @@ -59,7 +59,7 @@ let ((1,1), hiA), ((0,1), hiB)] -template odd*(i: int) : expr = +template odd*(i: int) : untyped = (i and 1) != 0 proc vidx(hg: HexGrid; col, row: int; i: HexVtxIndex) : Index = diff --git a/tests/ccgbugs/twrongrefcounting.nim b/tests/ccgbugs/twrongrefcounting.nim new file mode 100644 index 000000000..c0c3e0fc2 --- /dev/null +++ b/tests/ccgbugs/twrongrefcounting.nim @@ -0,0 +1,22 @@ +discard """ + output: '''ok''' + cmd: "nim c -r --gc:refc -d:useGcAssert -d:useSysAssert -d:fulldebug -d:smokeCycles $file" +""" +# bug #6234 +type + Foo = ref object + s: seq[Bar] + Bar = ref object + f: Foo + +proc test() = + var f = Foo.new() + for i in 0 .. 5: + f.s = @[] + for j in 0 .. 5: + var b = Bar.new() + b.f = f + f.s.add(b) + +test() +echo "ok" diff --git a/tests/closure/tboehmdeepcopy.nim b/tests/closure/tboehmdeepcopy.nim new file mode 100644 index 000000000..7c937ca10 --- /dev/null +++ b/tests/closure/tboehmdeepcopy.nim @@ -0,0 +1,18 @@ +discard """ + cmd: "nim c --gc:boehm $options $file" + output: '''meep''' + disabled: "windows" +""" + +proc callit(it: proc ()) = + it() + +proc main = + var outer = "meep" + proc x = + echo outer + var y: proc() + deepCopy(y, x) + callit(y) + +main() diff --git a/tests/closure/tdonotation.nim b/tests/closure/tdonotation.nim index 94eba8ddb..cc4f46bab 100644 --- a/tests/closure/tdonotation.nim +++ b/tests/closure/tdonotation.nim @@ -5,7 +5,9 @@ lost focus 1 lost focus 2 registered handler for UserEvent 1 registered handler for UserEvent 2 -registered handler for UserEvent 3''' +registered handler for UserEvent 3 +registered handler for UserEvent 4 +''' """ import future @@ -35,11 +37,14 @@ b.onFocusLost: b.onFocusLost do: echo "lost focus 2" -b.onUserEvent "UserEvent 1" do: +b.onUserEvent("UserEvent 1") do: discard b.onUserEvent "UserEvent 2": discard -b.onUserEvent("UserEvent 3", () => echo "event 3") +b.onUserEvent("UserEvent 3"): + discard + +b.onUserEvent("UserEvent 4", () => echo "event 4") diff --git a/tests/closure/tmacrobust1512.nim b/tests/closure/tmacrobust1512.nim index 95681e750..5f13e8286 100644 --- a/tests/closure/tmacrobust1512.nim +++ b/tests/closure/tmacrobust1512.nim @@ -2,109 +2,109 @@ import macros, strutils # https://github.com/nim-lang/Nim/issues/1512 -proc macrobust0 (raw_input: string) = +proc macrobust0(raw_input: string) = var output = "" - proc p1 (a:string) = - output.add (a) - - proc p2 (a:string) = p1 (a) - proc p3 (a:string) = p2 (a) - proc p4 (a:string) = p3 (a) - proc p5 (a:string) = p4 (a) - proc p6 (a:string) = p5 (a) - proc p7 (a:string) = p6 (a) - proc p8 (a:string) = p7 (a) - proc p9 (a:string) = p8 (a) - proc p10 (a:string) = p9 (a) - proc p11 (a:string) = p10 (a) - proc p12 (a:string) = p11 (a) - proc p13 (a:string) = p12 (a) - proc p14 (a:string) = p13 (a) - proc p15 (a:string) = p14 (a) - proc p16 (a:string) = p15 (a) - proc p17 (a:string) = p16 (a) - proc p18 (a:string) = p17 (a) - proc p19 (a:string) = p18 (a) - proc p20 (a:string) = p19 (a) + proc p1(a:string) = + output.add(a) + + proc p2(a:string) = p1(a) + proc p3(a:string) = p2(a) + proc p4(a:string) = p3(a) + proc p5(a:string) = p4(a) + proc p6(a:string) = p5(a) + proc p7(a:string) = p6(a) + proc p8(a:string) = p7(a) + proc p9(a:string) = p8(a) + proc p10(a:string) = p9(a) + proc p11(a:string) = p10(a) + proc p12(a:string) = p11(a) + proc p13(a:string) = p12(a) + proc p14(a:string) = p13(a) + proc p15(a:string) = p14(a) + proc p16(a:string) = p15(a) + proc p17(a:string) = p16(a) + proc p18(a:string) = p17(a) + proc p19(a:string) = p18(a) + proc p20(a:string) = p19(a) let input = $raw_input - for a in input.split (): - p20 (a) - p19 (a) - - - p18 (a) - p17 (a) - p16 (a) - p15 (a) - p14 (a) - p13 (a) - p12 (a) - p11 (a) - p10 (a) - p9 (a) - p8 (a) - p7 (a) - p6 (a) - p5 (a) - p4 (a) - p3 (a) - p2 (a) - p1 (a) + for a in input.split(): + p20(a) + p19(a) + + + p18(a) + p17(a) + p16(a) + p15(a) + p14(a) + p13(a) + p12(a) + p11(a) + p10(a) + p9(a) + p8(a) + p7(a) + p6(a) + p5(a) + p4(a) + p3(a) + p2(a) + p1(a) echo output -macro macrobust (raw_input: expr) : stmt = +macro macrobust(raw_input: untyped): untyped = var output = "" - proc p1 (a:string) = - output.add (a) - - proc p2 (a:string) = p1 (a) - proc p3 (a:string) = p2 (a) - proc p4 (a:string) = p3 (a) - proc p5 (a:string) = p4 (a) - proc p6 (a:string) = p5 (a) - proc p7 (a:string) = p6 (a) - proc p8 (a:string) = p7 (a) - proc p9 (a:string) = p8 (a) - proc p10 (a:string) = p9 (a) - proc p11 (a:string) = p10 (a) - proc p12 (a:string) = p11 (a) - proc p13 (a:string) = p12 (a) - proc p14 (a:string) = p13 (a) - proc p15 (a:string) = p14 (a) - proc p16 (a:string) = p15 (a) - proc p17 (a:string) = p16 (a) - proc p18 (a:string) = p17 (a) - proc p19 (a:string) = p18 (a) - proc p20 (a:string) = p19 (a) + proc p1(a:string) = + output.add(a) + + proc p2(a:string) = p1(a) + proc p3(a:string) = p2(a) + proc p4(a:string) = p3(a) + proc p5(a:string) = p4(a) + proc p6(a:string) = p5(a) + proc p7(a:string) = p6(a) + proc p8(a:string) = p7(a) + proc p9(a:string) = p8(a) + proc p10(a:string) = p9(a) + proc p11(a:string) = p10(a) + proc p12(a:string) = p11(a) + proc p13(a:string) = p12(a) + proc p14(a:string) = p13(a) + proc p15(a:string) = p14(a) + proc p16(a:string) = p15(a) + proc p17(a:string) = p16(a) + proc p18(a:string) = p17(a) + proc p19(a:string) = p18(a) + proc p20(a:string) = p19(a) let input = $raw_input - for a in input.split (): - p20 (a) - p19 (a) - - p18 (a) - p17 (a) - p16 (a) - p15 (a) - p14 (a) - p13 (a) - p12 (a) - p11 (a) - p10 (a) - p9 (a) - p8 (a) - p7 (a) - p6 (a) - p5 (a) - p4 (a) - p3 (a) - p2 (a) + for a in input.split(): + p20(a) + p19(a) + + p18(a) + p17(a) + p16(a) + p15(a) + p14(a) + p13(a) + p12(a) + p11(a) + p10(a) + p9(a) + p8(a) + p7(a) + p6(a) + p5(a) + p4(a) + p3(a) + p2(a) echo output discard result @@ -134,4 +134,4 @@ macrobust0 """ sdafsdaffsda sdfasadfsadf fsdasdafsdfa sdfasdfafsda sdfasdafsadf sdfasdafsdaf sdfasdafsdaf -""" \ No newline at end of file +""" diff --git a/tests/collections/ttableconstr.nim b/tests/collections/ttableconstr.nim index a9262e70e..884378a76 100644 --- a/tests/collections/ttableconstr.nim +++ b/tests/collections/ttableconstr.nim @@ -1,6 +1,6 @@ # Test if the new table constructor syntax works: -template ignoreExpr(e: expr): stmt {.immediate.} = +template ignoreExpr(e) = discard # test first class '..' syntactical citizen: diff --git a/tests/compiles/tcompiles.nim b/tests/compiles/tcompiles.nim index b3d9c17ce..1a21315c8 100644 --- a/tests/compiles/tcompiles.nim +++ b/tests/compiles/tcompiles.nim @@ -1,13 +1,15 @@ # test the new 'compiles' feature: -template supports(opr, x: expr): bool {.immediate.} = +template supports(opr, x: untyped): bool = compiles(opr(x)) or compiles(opr(x, x)) -template ok(x: expr): stmt = - static: assert(x) +template ok(x) = + static: + assert(x) -template no(x: expr): stmt = - static: assert(not x) +template no(x) = + static: + assert(not x) type TObj = object diff --git a/tests/concepts/matrix.nim b/tests/concepts/matrix.nim index a30cbe4f3..47a709f80 100644 --- a/tests/concepts/matrix.nim +++ b/tests/concepts/matrix.nim @@ -9,7 +9,6 @@ proc `[]=`*(M: var Matrix; m, n: int; v: M.T) = M.data[m * M.N + n] = v # Adapt the Matrix type to the concept's requirements -template Rows*(M: type Matrix): expr = M.M -template Cols*(M: type Matrix): expr = M.N +template Rows*(M: type Matrix): untyped = M.M +template Cols*(M: type Matrix): untyped = M.N template ValueType*(M: type Matrix): typedesc = M.T - diff --git a/tests/concepts/t3330.nim b/tests/concepts/t3330.nim index 04add2b6f..fcd5054ef 100644 --- a/tests/concepts/t3330.nim +++ b/tests/concepts/t3330.nim @@ -2,16 +2,16 @@ discard """ errormsg: "type mismatch: got (Bar[system.int])" nimout: ''' t3330.nim(40, 4) Error: type mismatch: got (Bar[system.int]) -but expected one of: +but expected one of: proc test(foo: Foo[int]) t3330.nim(25, 8) Hint: Non-matching candidates for add(k, string, T) -proc add[T](x: var seq[T]; y: T) -proc add(result: var string; x: float) proc add(x: var string; y: string) -proc add(x: var string; y: cstring) proc add(x: var string; y: char) proc add(result: var string; x: int64) +proc add(x: var string; y: cstring) +proc add(result: var string; x: float) proc add[T](x: var seq[T]; y: openArray[T]) +proc add[T](x: var seq[T]; y: T) t3330.nim(25, 8) template/generic instantiation from here t3330.nim(32, 6) Foo: 'bar.value' cannot be assigned to diff --git a/tests/concepts/tmanual.nim b/tests/concepts/tmanual.nim index 43290a6ad..c917f5022 100644 --- a/tests/concepts/tmanual.nim +++ b/tests/concepts/tmanual.nim @@ -14,10 +14,10 @@ t ''' """ -template accept(e: expr) = +template accept(e) = static: assert compiles(e) -template reject(e: expr) = +template reject(e) = static: assert(not compiles(e)) type @@ -40,4 +40,3 @@ takesContainer(@[4, 5, 6]) takesContainer(@["a", "b"]) takesContainer "test" reject takesContainer(10) - diff --git a/tests/concepts/tmodifiersinplace.nim b/tests/concepts/tmodifiersinplace.nim new file mode 100644 index 000000000..db5583929 --- /dev/null +++ b/tests/concepts/tmodifiersinplace.nim @@ -0,0 +1,30 @@ +type + VarContainer[T] = concept c + put(var c, T) + + AltVarContainer[T] = concept var c + put(c, T) + + NonVarContainer[T] = concept c + put(c, T) + + GoodContainer = object + x: int + + BadContainer = object + x: int + +proc put(x: BadContainer, y: int) = discard +proc put(x: var GoodContainer, y: int) = discard + +template ok(x) = assert(x) +template no(x) = assert(not(x)) + +static: + ok GoodContainer is VarContainer[int] + ok GoodContainer is AltVarContainer[int] + no BadContainer is VarContainer[int] + no BadContainer is AltVarContainer[int] + ok GoodContainer is NonVarContainer[int] + ok BadContainer is NonVarContainer[int] + diff --git a/tests/concepts/tstackconcept.nim b/tests/concepts/tstackconcept.nim index b6ead2c2b..2238dacb6 100644 --- a/tests/concepts/tstackconcept.nim +++ b/tests/concepts/tstackconcept.nim @@ -12,7 +12,7 @@ IMPLICIT VALUE TYPE NAME INT INT import typetraits, strutils -template reject(e: expr) = +template reject(e) = static: assert(not compiles(e)) type @@ -60,4 +60,3 @@ reject s.genericAlgorithm "x" reject s.genericAlgorithm 1.0 reject "str".implicitGeneric reject implicitGeneric(10) - diff --git a/tests/constructors/t5965_1.nim b/tests/constructors/t5965_1.nim new file mode 100644 index 000000000..9f947f859 --- /dev/null +++ b/tests/constructors/t5965_1.nim @@ -0,0 +1,10 @@ +discard """ + file: "t5965_1.nim" + line: 10 + errormsg: "incorrect object construction syntax" +""" + +type Foo = object + a, b, c: int + +discard Foo(a: 1, 2) diff --git a/tests/constructors/t5965_2.nim b/tests/constructors/t5965_2.nim new file mode 100644 index 000000000..a3f7174c9 --- /dev/null +++ b/tests/constructors/t5965_2.nim @@ -0,0 +1,10 @@ +discard """ + file: "t5965_2.nim" + line: 10 + errormsg: "incorrect object construction syntax" +""" + +type Foo = object + a: int + +discard Foo(a: 1, 2) diff --git a/tests/cpp/ttypeinfo.nim b/tests/cpp/ttypeinfo.nim index 1529c86e9..282c682b2 100644 --- a/tests/cpp/ttypeinfo.nim +++ b/tests/cpp/ttypeinfo.nim @@ -1,5 +1,22 @@ discard """ + output: '''100''' cmd: "nim cpp $file" """ import typeinfo + +#bug #6016 +type + Onion {.union.} = object + field1: int + field2: uint64 + + Stroom = Onion + + PStroom = ptr Stroom + +proc pstruct(u: PStroom) = + echo u.field2 + +var x = Onion(field1: 100) +pstruct(x.addr) \ No newline at end of file diff --git a/tests/discard/tdiscardable.nim b/tests/discard/tdiscardable.nim index 99adcfd30..662d2725a 100644 --- a/tests/discard/tdiscardable.nim +++ b/tests/discard/tdiscardable.nim @@ -13,7 +13,7 @@ q[float](0.8, 0.2) # bug #942 -template maybeMod(x: Tinteger, module:Natural):expr = +template maybeMod(x: Tinteger, module:Natural): untyped = if module > 0: x mod module else: x diff --git a/tests/exception/tdefer1.nim b/tests/exception/tdefer1.nim index cb3d09b01..b84ba7681 100644 --- a/tests/exception/tdefer1.nim +++ b/tests/exception/tdefer1.nim @@ -10,7 +10,7 @@ A''' # bug #1742 -template test(): expr = +template test(): untyped = let a = 0 defer: echo "hi" a @@ -29,7 +29,7 @@ template atFuncEnd = defer: echo "B" -template testB(): expr = +template testB(): untyped = let a = 0 defer: echo "hi" # Delete this line to make it work a diff --git a/tests/exception/tfinally3.nim b/tests/exception/tfinally3.nim index 037ca9553..6098672a2 100644 --- a/tests/exception/tfinally3.nim +++ b/tests/exception/tfinally3.nim @@ -1,10 +1,7 @@ discard """ file: "tfinally3.nim" - output: '''false -Within finally->try -Traceback (most recent call last) -tfinally3.nim(24) tfinally3 -Error: unhandled exception: First [Exception]''' + outputsub: '''false +Within finally->try''' exitCode: 1 """ # Test break in try statement: diff --git a/tests/fields/tfields_in_template.nim b/tests/fields/tfields_in_template.nim index 9352a7a51..b7d5d2343 100644 --- a/tests/fields/tfields_in_template.nim +++ b/tests/fields/tfields_in_template.nim @@ -9,7 +9,7 @@ for name, value in (n: "v").fieldPairs: echo name # This doesn't compile - "expression 'name' has no type (or is ambiguous)". -template wrapper: stmt = +template wrapper: typed = for name, value in (n: "v").fieldPairs: echo name wrapper() diff --git a/tests/float/tfloat7.nim b/tests/float/tfloat7.nim index 2337d1dd4..5fd0d43d9 100644 --- a/tests/float/tfloat7.nim +++ b/tests/float/tfloat7.nim @@ -10,7 +10,7 @@ passed.''' """ import strutils -template expect_fail(x: expr) = +template expect_fail(x) = try: discard x echo("expected to fail!") diff --git a/tests/generics/tgeneric3.nim b/tests/generics/tgeneric3.nim index 0dbd5b03c..d014eb998 100644 --- a/tests/generics/tgeneric3.nim +++ b/tests/generics/tgeneric3.nim @@ -66,7 +66,7 @@ proc setItem[T,D](Akey: T, Avalue: D, ANode: PNode[T,D]): ref TItem[T,D] {.inlin proc cmp[T:int8|int16|int32|int64|int] (a,b: T): T {.inline.} = return a-b -template binSearchImpl *(docmp: expr) {.immediate.} = +template binSearchImpl *(docmp: untyped) = var bFound = false result = 0 var H = haystack.len - 1 diff --git a/tests/generics/tgenerictmpl.nim b/tests/generics/tgenerictmpl.nim index c71ce4e2e..e18f020c2 100644 --- a/tests/generics/tgenerictmpl.nim +++ b/tests/generics/tgenerictmpl.nim @@ -5,7 +5,7 @@ discard """ # bug #3498 -template defaultOf[T](t: T): expr = (var d: T; d) +template defaultOf[T](t: T): untyped = (var d: T; d) echo defaultOf(1) #<- excpected 0 diff --git a/tests/generics/tgenerictmpl2.nim b/tests/generics/tgenerictmpl2.nim index 0ecaf9ded..ac92d3281 100644 --- a/tests/generics/tgenerictmpl2.nim +++ b/tests/generics/tgenerictmpl2.nim @@ -27,5 +27,5 @@ ttmpl[int] #<- crash case #3 # but still allow normal use of [] on non-generic templates -template tarr: expr = [1, 2, 3, 4] +template tarr: untyped = [1, 2, 3, 4] echo tarr[1] diff --git a/tests/generics/tunique_type.nim b/tests/generics/tunique_type.nim index da2f9e4b2..ccb367ac8 100644 --- a/tests/generics/tunique_type.nim +++ b/tests/generics/tunique_type.nim @@ -36,7 +36,7 @@ proc derefExpr(exprRef: string): NimNode {.compileTime.} = type Mapped[Input; predicate: static[string]] = object input: Input -macro map(input, predicate: expr): expr = +macro map(input, predicate: untyped): untyped = let predicate = callsite()[2] newNimNode(nnkObjConstr).add( newNimNode(nnkBracketExpr).add( @@ -47,7 +47,7 @@ macro map(input, predicate: expr): expr = ident"input", input)) proc `[]`(m: Mapped, i: int): auto = - macro buildResult: expr = + macro buildResult: untyped = newCall( derefExpr(m.predicate), newNimNode(nnkBracketExpr).add( diff --git a/tests/gensym/tgensym.nim b/tests/gensym/tgensym.nim index 3c85b0b83..e33a2783f 100644 --- a/tests/gensym/tgensym.nim +++ b/tests/gensym/tgensym.nim @@ -2,7 +2,7 @@ discard """ output: "123100" """ -template hygienic(val: expr) = +template hygienic(val) = var x = val stdout.write x diff --git a/tests/gensym/tgensymgeneric.nim b/tests/gensym/tgensymgeneric.nim index 54390a4ef..9963ba808 100644 --- a/tests/gensym/tgensymgeneric.nim +++ b/tests/gensym/tgensymgeneric.nim @@ -1,3 +1,7 @@ +discard """ + output: '''true''' +""" + # We need to open the gensym'ed symbol again so that the instantiation # creates a fresh copy; but this is wrong the very first reason for gensym # is that scope rules cannot be used! So simply removing 'sfGenSym' does @@ -28,4 +32,23 @@ var let x = gen(a) let y = gen(b) -echo x.x, " ", y.x +doAssert x.x == 123 +doAssert y.x == "abc" + +# test symbol equality + +import macros + +static: + let sym1 = genSym() + let sym2 = genSym() + let sym3 = sym1 + let nimsym = sym1.symbol + doAssert sym1 == sym1 + doAssert sym2 != sym3 + doAssert sym2.symbol != sym3.symbol + doAssert sym3 == sym1 + doAssert sym1.symbol == sym1.symbol + doAssert nimsym == nimsym + +echo "true" diff --git a/tests/iter/tclosureiters.nim b/tests/iter/tclosureiters.nim index 0eb624a8c..37313d4d7 100644 --- a/tests/iter/tclosureiters.nim +++ b/tests/iter/tclosureiters.nim @@ -18,7 +18,8 @@ discard """ 0 0 1 -2''' +2 +70''' """ when true: @@ -71,3 +72,10 @@ for x in infinite.take(3): let inf = infinite for x in inf.take(3): echo x + +# bug #3583 +proc foo(f: (iterator(): int)) = + for i in f(): echo i + +let fIt = iterator(): int = yield 70 +foo fIt diff --git a/tests/js/tjsffi.nim b/tests/js/tjsffi.nim index e4aad4b99..325ab6366 100644 --- a/tests/js/tjsffi.nim +++ b/tests/js/tjsffi.nim @@ -309,11 +309,11 @@ block: on("click") do (e: Event): console.log e - jslib.on "reloaded" do: + jslib.on("reloaded") do: console.log jsarguments[0] # this test case is different from the above, because # `subscribe` is not overloaded in the current scope - jslib.subscribe "updates": + jslib.subscribe("updates"): console.log jsarguments[0] diff --git a/tests/js/ttryexceptnewsyntax.nim b/tests/js/ttryexceptnewsyntax.nim new file mode 100644 index 000000000..2573c3727 --- /dev/null +++ b/tests/js/ttryexceptnewsyntax.nim @@ -0,0 +1,13 @@ +discard """ + output: '''hello''' +""" + +type + MyException = ref Exception + +#bug #5986 + +try: + raise MyException(msg: "hello") +except MyException as e: + echo e.msg diff --git a/tests/lexer/tind1.nim b/tests/lexer/tind1.nim index 6a975d5be..8a2aea9b2 100644 --- a/tests/lexer/tind1.nim +++ b/tests/lexer/tind1.nim @@ -11,17 +11,15 @@ var x = if 4 != 5: else: "no" -macro mymacro(n: expr): stmt {.immediate.} = nil +macro mymacro(n): untyped {.immediate.} = + discard mymacro: echo "test" else: echo "else part" - if 4 == 3: echo "bug" else: echo "no bug" - - diff --git a/tests/macros/tbindsym.nim b/tests/macros/tbindsym.nim index e1e3b5112..6289d3eb2 100644 --- a/tests/macros/tbindsym.nim +++ b/tests/macros/tbindsym.nim @@ -11,7 +11,7 @@ type TTextKind = enum TFoo, TBar -macro test: stmt = +macro test: untyped = var x = @[TFoo, TBar] result = newStmtList() for i in x: diff --git a/tests/macros/tbugs.nim b/tests/macros/tbugs.nim index 1bfce6bc4..990edf1e2 100644 --- a/tests/macros/tbugs.nim +++ b/tests/macros/tbugs.nim @@ -26,7 +26,7 @@ iterator test2(f: string): Foo = for i in f: yield Foo(s: i) -macro test(): stmt = +macro test(): untyped = for i in test2("asdf"): echo i.s @@ -39,7 +39,7 @@ import macros type TType = tuple[s: string] -macro echotest(): stmt = +macro echotest(): untyped = var t: TType t.s = "" t.s.add("test") @@ -61,7 +61,7 @@ proc get_data(d: Td) : string {.compileTime.} = #result.add("aa") # B #result = result & "aa" # C -macro m(s:static[Td]) : stmt = +macro m(s:static[Td]) : untyped = echo get_data(s) echo get_data(s) result = newEmptyNode() @@ -77,7 +77,7 @@ proc nilcheck(): NimNode {.compileTime.} = echo(result.isNil) # true echo(repr(result)) # nil -macro testnilcheck(): stmt = +macro testnilcheck(): untyped = result = newNimNode(nnkStmtList) discard nilcheck() @@ -95,10 +95,10 @@ echo c[0] # bug #3046 -macro sampleMacroInt(i: int): stmt = +macro sampleMacroInt(i: int): untyped = echo i.intVal -macro sampleMacroBool(b: bool): stmt = +macro sampleMacroBool(b: bool): untyped = echo b.boolVal sampleMacroInt(42) diff --git a/tests/macros/tcomplexecho.nim b/tests/macros/tcomplexecho.nim index f7f933c1c..0b70a3ef7 100644 --- a/tests/macros/tcomplexecho.nim +++ b/tests/macros/tcomplexecho.nim @@ -10,7 +10,7 @@ OK import macros # Bug from the forum -macro addEcho1(s: untyped): stmt = +macro addEcho1(s: untyped): untyped = s.body.add(newCall("echo", newStrLitNode("OK"))) result = s @@ -32,7 +32,7 @@ proc foo(): seq[NimNode] {.compiletime.} = result.add test() result.add parseExpr("echo(5+56)") -macro bar(): stmt = +macro bar(): typed = result = newNimNode(nnkStmtList) let x = foo() for xx in x: diff --git a/tests/macros/tdebugstmt.nim b/tests/macros/tdebugstmt.nim index 421f8fd14..740ae7b05 100644 --- a/tests/macros/tdebugstmt.nim +++ b/tests/macros/tdebugstmt.nim @@ -6,7 +6,7 @@ x: some string''' import macros -macro debug(n: varargs[expr]): stmt = +macro debug(n: varargs[untyped]): untyped = # `n` is a Nim AST that contains the whole macro invocation # this macro returns a list of statements: result = newNimNode(nnkStmtList, n) diff --git a/tests/macros/tdumpast2.nim b/tests/macros/tdumpast2.nim index 6b694fa77..c4c591b2a 100644 --- a/tests/macros/tdumpast2.nim +++ b/tests/macros/tdumpast2.nim @@ -21,7 +21,7 @@ proc dumpit(n: NimNode): string {.compileTime.} = add(result, dumpit(n[j])) add(result, ")") -macro dumpAST(n: stmt): stmt {.immediate.} = +macro dumpAST(n): untyped = # dump AST as a side-effect and return the inner node let n = callsite() echo dumpit(n) diff --git a/tests/macros/tdumpastgen.nim b/tests/macros/tdumpastgen.nim new file mode 100644 index 000000000..faed77225 --- /dev/null +++ b/tests/macros/tdumpastgen.nim @@ -0,0 +1,25 @@ +discard """ +msg: '''nnkStmtList.newTree( + nnkVarSection.newTree( + nnkIdentDefs.newTree( + newIdentNode(!"x"), + newEmptyNode(), + nnkCall.newTree( + nnkDotExpr.newTree( + newIdentNode(!"foo"), + newIdentNode(!"create") + ), + newLit(56) + ) + ) + ) +)''' +""" + +# disabled; can't work as the output is done by the compiler + +import macros + +dumpAstGen: + var x = foo.create(56) + diff --git a/tests/macros/texprcolonexpr.nim b/tests/macros/texprcolonexpr.nim index 3b2c86b77..59c799771 100644 --- a/tests/macros/texprcolonexpr.nim +++ b/tests/macros/texprcolonexpr.nim @@ -13,7 +13,7 @@ Infix """ import macros -macro def(x: stmt): stmt {.immediate.} = +macro def(x): untyped = echo treeRepr(x) def name(a, b:cint) => nil diff --git a/tests/macros/tgenericparams.nim b/tests/macros/tgenericparams.nim new file mode 100644 index 000000000..d656f045a --- /dev/null +++ b/tests/macros/tgenericparams.nim @@ -0,0 +1,13 @@ +discard """ +output: '''proc foo[T, N: static[int]]() +proc foo[T; N: static[int]]()''' +""" +import macros + +macro test():string = + let expr0 = "proc foo[T, N: static[int]]()" + let expr1 = "proc foo[T; N: static[int]]()" + + $toStrLit(parseExpr(expr0)) & "\n" & $toStrLit(parseExpr(expr1)) + +echo test() diff --git a/tests/macros/tgensym.nim b/tests/macros/tgensym.nim index a4d1a3606..955168939 100644 --- a/tests/macros/tgensym.nim +++ b/tests/macros/tgensym.nim @@ -11,7 +11,7 @@ proc convertReturns(node, retFutureSym: NimNode): NimNode {.compileTime.} = for i in 0 .. <node.len: result[i] = convertReturns(node[i], retFutureSym) -macro async2(prc: stmt): stmt {.immediate.} = +macro async2(prc: untyped): untyped = expectKind(prc, nnkProcDef) var outerProcBody = newNimNode(nnkStmtList) diff --git a/tests/macros/tgentemplates.nim b/tests/macros/tgentemplates.nim index 764b94bc7..301d58c6a 100644 --- a/tests/macros/tgentemplates.nim +++ b/tests/macros/tgentemplates.nim @@ -20,7 +20,7 @@ proc parse_template(node: NimNode, value: string) {.compiletime.} = while index < value.len and parse_until_symbol(node, value, index): discard -macro tmpli*(body: expr): stmt = +macro tmpli*(body: untyped): typed = result = newStmtList() result.add parseExpr("result = \"\"") result.parse_template body[1].strVal diff --git a/tests/macros/tgettype.nim b/tests/macros/tgettype.nim index 0eab6c0a0..fa02bce57 100644 --- a/tests/macros/tgettype.nim +++ b/tests/macros/tgettype.nim @@ -10,11 +10,18 @@ type name : string password : string -macro testUser: expr = - return newLit(User.getType.lispRepr) +macro testUser: string = + result = newLit(User.getType.lispRepr) -macro testGeneric(T: typedesc[Model]): expr = - return newLit(T.getType.lispRepr) +macro testGeneric(T: typedesc[Model]): string= + result = newLit(T.getType.lispRepr) echo testUser echo User.testGeneric + +macro assertVoid(e: typed): untyped = + assert(getTypeInst(e).typeKind == ntyVoid) + +proc voidProc() = discard + +assertVoid voidProc() diff --git a/tests/macros/tgettypeinst.nim b/tests/macros/tgettypeinst.nim index f89aa5e0b..8e1d9bc13 100644 --- a/tests/macros/tgettypeinst.nim +++ b/tests/macros/tgettypeinst.nim @@ -22,7 +22,7 @@ proc symToIdent(x: NimNode): NimNode = result.add symToIdent(c) # check getTypeInst and getTypeImpl for given symbol x -macro testX(x,inst0: typed; recurse: static[bool]; implX: stmt): typed = +macro testX(x,inst0: typed; recurse: static[bool]; implX: typed): typed = # check that getTypeInst(x) equals inst0 let inst = x.getTypeInst let instr = inst.symToIdent.treeRepr diff --git a/tests/macros/tidgen.nim b/tests/macros/tidgen.nim index 2fe9e0f82..88322b227 100644 --- a/tests/macros/tidgen.nim +++ b/tests/macros/tidgen.nim @@ -8,7 +8,7 @@ import macros var gid {.compileTime.} = 3 -macro genId(): expr = +macro genId(): int = result = newIntLitNode(gid) inc gid diff --git a/tests/macros/tmacro1.nim b/tests/macros/tmacro1.nim index 2dd5c31df..ac6bd02a5 100644 --- a/tests/macros/tmacro1.nim +++ b/tests/macros/tmacro1.nim @@ -2,7 +2,7 @@ import macros from uri import `/` -macro test*(a: stmt): stmt {.immediate.} = +macro test*(a: untyped): untyped = var nodes: tuple[a, b: int] nodes.a = 4 nodes[1] = 45 @@ -20,4 +20,3 @@ macro test*(a: stmt): stmt {.immediate.} = test: "hi" - diff --git a/tests/macros/tmacro2.nim b/tests/macros/tmacro2.nim index 17f312925..72972c0c1 100644 --- a/tests/macros/tmacro2.nim +++ b/tests/macros/tmacro2.nim @@ -12,7 +12,7 @@ proc testBlock(): string {.compileTime.} = echo "outer block" result = "ta-da" -macro mac(n: expr): expr = +macro mac(n: typed): string = let n = callsite() expectKind(n, nnkCall) expectLen(n, 2) diff --git a/tests/macros/tmacro3.nim b/tests/macros/tmacro3.nim index d7421ff7f..a1dc4f371 100644 --- a/tests/macros/tmacro3.nim +++ b/tests/macros/tmacro3.nim @@ -8,7 +8,7 @@ type TA = tuple[a: int] PA = ref TA -macro test*(a: stmt): stmt {.immediate.} = +macro test*(a: untyped): untyped = var val: PA new(val) val.a = 4 @@ -16,7 +16,7 @@ macro test*(a: stmt): stmt {.immediate.} = test: "hi" -macro test2*(a: stmt): stmt {.immediate.} = +macro test2*(a: untyped): untyped = proc testproc(recurse: int) = echo "Thats weird" var o : NimNode = nil @@ -28,4 +28,3 @@ macro test2*(a: stmt): stmt {.immediate.} = test2: "hi" - diff --git a/tests/macros/tmacro4.nim b/tests/macros/tmacro4.nim index fb07941a9..164afaeb7 100644 --- a/tests/macros/tmacro4.nim +++ b/tests/macros/tmacro4.nim @@ -5,7 +5,7 @@ discard """ import macros, strutils -macro test_macro*(s: string, n: stmt): stmt {.immediate.} = +macro test_macro*(s: string, n: untyped): untyped = result = newNimNode(nnkStmtList) var ass : NimNode = newNimNode(nnkAsgn) add(ass, newIdentNode("str")) @@ -16,4 +16,3 @@ when isMainModule: test_macro(str): var i : integer = 123 echo str - diff --git a/tests/macros/tmacro5.nim b/tests/macros/tmacro5.nim index d7a4fe8c8..1c60e1ffd 100644 --- a/tests/macros/tmacro5.nim +++ b/tests/macros/tmacro5.nim @@ -3,7 +3,7 @@ import macros,json var decls{.compileTime.}: seq[NimNode] = @[] var impls{.compileTime.}: seq[NimNode] = @[] -macro importImpl_forward(name, returns): stmt {.immediate.} = +macro importImpl_forward(name, returns: untyped): untyped = result = newNimNode(nnkEmpty) var func_name = newNimNode(nnkAccQuoted) func_name.add newIdentNode("import") @@ -19,7 +19,7 @@ macro importImpl_forward(name, returns): stmt {.immediate.} = res[3].add returns var p1 = newNimNode(nnkIdentDefs) p1.add newIdentNode("dat") - p1.add newIdentNOde("PJsonNode") + p1.add newIdentNOde("JsonNode") p1.add newNimNode(nnkEmpty) res[3].add p1 var p2 = newNimNode(nnkIdentDefs) @@ -38,7 +38,7 @@ macro importImpl_forward(name, returns): stmt {.immediate.} = decls.add res echo(repr(res)) -macro importImpl(name, returns: expr, body: stmt): stmt {.immediate.} = +macro importImpl(name, returns, body: untyped): typed = #var res = getAST(importImpl_forward(name, returns)) discard getAST(importImpl_forward(name, returns)) var res = copyNimTree(decls[decls.high]) @@ -46,7 +46,7 @@ macro importImpl(name, returns: expr, body: stmt): stmt {.immediate.} = echo repr(res) impls.add res -macro okayy:stmt = +macro okayy: typed = result = newNimNode(nnkStmtList) for node in decls: result.add node for node in impls: result.add node diff --git a/tests/macros/tmacro_in_template.nim b/tests/macros/tmacro_in_template.nim index 8f7753cea..9668495df 100644 --- a/tests/macros/tmacro_in_template.nim +++ b/tests/macros/tmacro_in_template.nim @@ -2,8 +2,8 @@ # bug #1944 import macros -template t(e: expr): stmt = - macro m(eNode: expr): stmt = +template t(e: untyped): untyped = + macro m(eNode: untyped): untyped = echo eNode.treeRepr m e diff --git a/tests/macros/tmacroaspragma.nim b/tests/macros/tmacroaspragma.nim index 0e5c352b3..5f06f2425 100644 --- a/tests/macros/tmacroaspragma.nim +++ b/tests/macros/tmacroaspragma.nim @@ -1,8 +1,7 @@ import macros -macro foo(x: stmt): stmt = +macro foo(x: untyped): untyped = echo treerepr(callsite()) result = newNimNode(nnkStmtList) proc zoo() {.foo.} = echo "hi" - diff --git a/tests/macros/tmacros1.nim b/tests/macros/tmacros1.nim index 1a1073a44..9e3ab028b 100644 --- a/tests/macros/tmacros1.nim +++ b/tests/macros/tmacros1.nim @@ -5,7 +5,7 @@ discard """ import macros, strutils -macro outterMacro*(n: stmt): stmt {.immediate.} = +macro outterMacro*(n, blck: untyped): untyped = let n = callsite() var j : string = "hi" proc innerProc(i: int): string = @@ -27,5 +27,3 @@ var str: string outterMacro(str): "hellow" echo str - - diff --git a/tests/macros/tmacrostmt.nim b/tests/macros/tmacrostmt.nim index 23e2f358c..6f648958f 100644 --- a/tests/macros/tmacrostmt.nim +++ b/tests/macros/tmacrostmt.nim @@ -1,5 +1,5 @@ import macros -macro case_token(n: stmt): stmt {.immediate.} = +macro case_token(n: untyped): untyped {.immediate.} = # creates a lexical analyzer from regular expressions # ... (implementation is an exercise for the reader :-) nil @@ -18,7 +18,7 @@ case_token: inc i #bug #488 -macro foo: stmt = +macro foo: typed = var exp = newCall("whatwhat", newIntLitNode(1)) if compiles(getAst(exp)): return exp else: echo "Does not compute!" diff --git a/tests/macros/tmacrotypes.nim b/tests/macros/tmacrotypes.nim index 991668930..e8a68c34d 100644 --- a/tests/macros/tmacrotypes.nim +++ b/tests/macros/tmacrotypes.nim @@ -5,7 +5,7 @@ int''' import macros -macro checkType(ex: stmt; expected: expr): stmt = +macro checkType(ex: typed; expected: string): untyped = var t = ex.getType() echo t diff --git a/tests/macros/tnewlit.nim b/tests/macros/tnewlit.nim index 69245d076..3ba1e09e1 100644 --- a/tests/macros/tnewlit.nim +++ b/tests/macros/tnewlit.nim @@ -138,3 +138,12 @@ macro test_newLit_ComposedType: untyped = result = newLit(ct) doAssert test_newLit_ComposedType == ComposedType(mt: MyType(a: 123, b:"abc"), arr: [1,2,3,4], data: @[1.byte, 3, 7, 127]) + +macro test_newLit_empty_seq_string: untyped = + var strSeq = newSeq[string](0) + result = newLit(strSeq) + +block: + # x needs to be of type seq[string] + var x = test_newLit_empty_seq_string + x.add("xyz") diff --git a/tests/macros/tnodecompare.nim b/tests/macros/tnodecompare.nim index b9cf7df48..5ffb495b1 100644 --- a/tests/macros/tnodecompare.nim +++ b/tests/macros/tnodecompare.nim @@ -11,7 +11,7 @@ static: nodeB.strVal = "this is a different comment" doAssert nodeA != nodeB -macro test(a: typed, b: typed): expr = +macro test(a: typed, b: typed): untyped = newLit(a == b) doAssert test(1, 1) == true @@ -29,10 +29,10 @@ var a, b: int doAssert test(a, a) == true doAssert test(a, b) == false -macro test2: expr = +macro test2: untyped = newLit(bindSym"Obj" == bindSym"Obj") -macro test3: expr = +macro test3: untyped = newLit(bindSym"Obj" == bindSym"Other") doAssert test2() == true diff --git a/tests/macros/tquotewords.nim b/tests/macros/tquotewords.nim index 48fcafd62..fa00ba9de 100644 --- a/tests/macros/tquotewords.nim +++ b/tests/macros/tquotewords.nim @@ -6,7 +6,7 @@ discard """ import macros -macro quoteWords(n: varargs[expr]): expr {.immediate.} = +macro quoteWords(n: varargs[untyped]): untyped = let n = callsite() result = newNimNode(nnkBracket, n) for i in 1..n.len-1: @@ -21,6 +21,3 @@ for w in items(myWordList): s.add(w) echo s #OUT thisanexample - - - diff --git a/tests/macros/trecmacro.nim b/tests/macros/trecmacro.nim index 28b6db530..69ebe3da3 100644 --- a/tests/macros/trecmacro.nim +++ b/tests/macros/trecmacro.nim @@ -4,7 +4,7 @@ discard """ errormsg: "recursive dependency: 'dump'" """ -macro dump(n: stmt): stmt = +macro dump(n: untyped): untyped = dump(n) if kind(n) == nnkNone: nil diff --git a/tests/macros/treturnsempty.nim b/tests/macros/treturnsempty.nim index 7af26a747..a5a678af3 100644 --- a/tests/macros/treturnsempty.nim +++ b/tests/macros/treturnsempty.nim @@ -3,10 +3,9 @@ discard """ line: 11 """ # bug #2372 -macro foo(dummy: int): stmt = +macro foo(dummy: int): untyped = discard proc takeStr(s: string) = echo s takeStr foo(12) - diff --git a/tests/macros/tsametype.nim b/tests/macros/tsametype.nim index 34296015f..865fb4cb8 100644 --- a/tests/macros/tsametype.nim +++ b/tests/macros/tsametype.nim @@ -13,7 +13,7 @@ false''' import macros -macro same(a: typedesc, b: typedesc): expr = +macro same(a: typedesc, b: typedesc): untyped = newLit(a.getType[1].sameType b.getType[1]) echo same(int, int) diff --git a/tests/macros/tstaticparamsmacro.nim b/tests/macros/tstaticparamsmacro.nim index f6ecb3a9f..ea59936e0 100644 --- a/tests/macros/tstaticparamsmacro.nim +++ b/tests/macros/tstaticparamsmacro.nim @@ -25,7 +25,7 @@ type const data: Tconfig = (@["aa", "bb"], @[11, 22]) -macro mymacro(data: static[TConfig]): stmt = +macro mymacro(data: static[TConfig]): untyped = echo "letters" for s in items(data.letters): echo s @@ -43,10 +43,10 @@ const a : Ta = @[(11, 22), (33, 44)] b : Tb = (@[55,66], @[77, 88]) -macro mA(data: static[Ta]): stmt = +macro mA(data: static[Ta]): untyped = echo "AST a \n", repr(data) -macro mB(data: static[Tb]): stmt = +macro mB(data: static[Tb]): untyped = echo "AST b \n", repr(data) echo data.e[0] @@ -56,13 +56,13 @@ mB(b) type Foo[N: static[int], Z: static[string]] = object -macro staticIntMacro(f: static[int]): stmt = echo f +macro staticIntMacro(f: static[int]): untyped = echo f staticIntMacro 10 var x: Foo[20, "Test"] -macro genericMacro[N; Z: static[string]](f: Foo[N, Z], ll = 3, zz = 12): stmt = +macro genericMacro[N; Z: static[string]](f: Foo[N, Z], ll = 3, zz = 12): untyped = echo N, Z genericMacro x diff --git a/tests/macros/tstringinterp.nim b/tests/macros/tstringinterp.nim index bc79cdaba..305f40ac5 100644 --- a/tests/macros/tstringinterp.nim +++ b/tests/macros/tstringinterp.nim @@ -9,7 +9,7 @@ proc concat(strings: varargs[string]): string = result = newString(0) for s in items(strings): result.add(s) -template processInterpolations(e: expr) = +template processInterpolations(e) = var s = e[1].strVal for f in interpolatedFragments(s): case f.kind @@ -17,7 +17,7 @@ template processInterpolations(e: expr) = of ikDollar: addDollar() of ikVar, ikExpr: addExpr(newCall("$", parseExpr(f.value))) -macro formatStyleInterpolation(e: expr): expr = +macro formatStyleInterpolation(e: untyped): untyped = let e = callsite() var formatString = "" @@ -41,7 +41,7 @@ macro formatStyleInterpolation(e: expr): expr = result[1].strVal = formatString result[2] = arrayNode -macro concatStyleInterpolation(e: expr): expr = +macro concatStyleInterpolation(e: untyped): untyped = let e = callsite() var args: seq[NimNode] newSeq(args, 0) @@ -71,4 +71,3 @@ var s2 = formatStyleInterpolation"Hello ${bob}, ${sum(alice.len, bob.len, 2)}$$" write(stdout, s1 & " | " & s2) - diff --git a/tests/macros/ttryparseexpr.nim b/tests/macros/ttryparseexpr.nim index c7bbc8e5b..54442b662 100644 --- a/tests/macros/ttryparseexpr.nim +++ b/tests/macros/ttryparseexpr.nim @@ -5,7 +5,7 @@ discard """ # feature request #1473 import macros -macro test(text: string): expr = +macro test(text: string): untyped = try: result = parseExpr(text.strVal) except ValueError: diff --git a/tests/macros/tvarnimnode.nim b/tests/macros/tvarnimnode.nim index ab0f66caa..26c9b1f1a 100644 --- a/tests/macros/tvarnimnode.nim +++ b/tests/macros/tvarnimnode.nim @@ -10,7 +10,7 @@ proc test(f: var NimNode) {.compileTime.} = f = newNimNode(nnkStmtList) f.add newCall(newIdentNode("echo"), newLit(10)) -macro blah(prc: stmt): stmt = +macro blah(prc: untyped): untyped = result = prc test(result) diff --git a/tests/macros/typesapi.nim b/tests/macros/typesapi.nim index 670b39c9e..cdbfc0ad2 100644 --- a/tests/macros/typesapi.nim +++ b/tests/macros/typesapi.nim @@ -8,7 +8,7 @@ proc (x: int) => typeDesc[proc[void, int]]''' import macros -macro showType(t:stmt): stmt = +macro showType(t:typed): untyped = let ty = t.getType echo t.repr, " => ", ty.repr diff --git a/tests/macros/typesapi2.nim b/tests/macros/typesapi2.nim index 2e59d2154..0130049c0 100644 --- a/tests/macros/typesapi2.nim +++ b/tests/macros/typesapi2.nim @@ -2,7 +2,7 @@ # be used as a type import macros -macro testTypesym (t:stmt): expr = +macro testTypesym (t:typed): untyped = var ty = t.getType if ty.typekind == ntyTypedesc: # skip typedesc get to the real type @@ -31,7 +31,7 @@ static: assert(ref int is testTypesym(ref int)) static: assert(void is testTypesym(void)) -macro tts2 (t:stmt, idx:int): expr = +macro tts2 (t:typed, idx:int): untyped = var ty = t.getType if ty.typekind == ntyTypedesc: # skip typedesc get to the real type @@ -46,4 +46,3 @@ static: assert(tts2(TestFN2, 1) is string) assert(tts2(TestFN2, 2) is int) assert(tts2(TestFN2, 3) is float) - diff --git a/tests/manyloc/keineschweine/keineschweine.nim b/tests/manyloc/keineschweine/keineschweine.nim index 804a22852..c0f1bc031 100644 --- a/tests/manyloc/keineschweine/keineschweine.nim +++ b/tests/manyloc/keineschweine/keineschweine.nim @@ -212,9 +212,10 @@ proc free(obj: PLiveBullet) = obj.record = nil -template newExplosion(obj, animation): stmt = +template newExplosion(obj, animation) = explosions.add(newAnimation(animation, AnimOnce, obj.body.getPos.cp2sfml, obj.body.getAngle)) -template newExplosion(obj, animation, angle): stmt = + +template newExplosion(obj, animation, angle) = explosions.add(newAnimation(animation, AnimOnce, obj.body.getPos.cp2sfml, angle)) proc explode*(b: PLiveBullet) = diff --git a/tests/metatype/tbindtypedesc.nim b/tests/metatype/tbindtypedesc.nim index 4f027407b..b287aad01 100644 --- a/tests/metatype/tbindtypedesc.nim +++ b/tests/metatype/tbindtypedesc.nim @@ -16,10 +16,10 @@ type TBar = tuple x, y: int -template accept(e: expr) = +template accept(e) = static: assert(compiles(e)) -template reject(e: expr) = +template reject(e) = static: assert(not compiles(e)) proc genericParamRepeated[T: typedesc](a: T, b: T) = diff --git a/tests/metatype/tmatrix.nim b/tests/metatype/tmatrix.nim index 5acd4389e..4fd32a932 100644 --- a/tests/metatype/tmatrix.nim +++ b/tests/metatype/tmatrix.nim @@ -9,7 +9,7 @@ type data: seq[float] fWidth, fHeight: int -template `|`(x, y: int): expr = y * m.fWidth + x +template `|`(x, y: int): untyped = y * m.fWidth + x proc createMatrix*(width, height: int): TMatrix = result.fWidth = width diff --git a/tests/metatype/tsemistatic.nim b/tests/metatype/tsemistatic.nim index a13175ba8..3f36abde9 100644 --- a/tests/metatype/tsemistatic.nim +++ b/tests/metatype/tsemistatic.nim @@ -7,7 +7,7 @@ type semistatic[T] = static[T] or T -template isStatic*(x): expr = +template isStatic*(x): bool = compiles(static(x)) proc foo(x: semistatic[int]) = diff --git a/tests/metatype/tstatic_overloading.nim b/tests/metatype/tstatic_overloading.nim index ce51052b7..9c065e48d 100644 --- a/tests/metatype/tstatic_overloading.nim +++ b/tests/metatype/tstatic_overloading.nim @@ -5,6 +5,6 @@ import macros proc impl(op: static[int]) = echo "impl 1 called" proc impl(op: static[int], init: int) = echo "impl 2 called" -macro wrapper2: stmt = newCall(bindSym"impl", newLit(0), newLit(0)) +macro wrapper2: untyped = newCall(bindSym"impl", newLit(0), newLit(0)) wrapper2() # Code generation for this fails. diff --git a/tests/metatype/tstaticparammacro.nim b/tests/metatype/tstaticparammacro.nim index 5c7c5e6af..bd3295874 100644 --- a/tests/metatype/tstaticparammacro.nim +++ b/tests/metatype/tstaticparammacro.nim @@ -26,7 +26,7 @@ type const data: Tconfig = (@["aa", "bb"], @[11, 22]) -macro mymacro(data: static[TConfig]): stmt = +macro mymacro(data: static[TConfig]) = echo "letters" for s in items(data.letters): echo s @@ -44,10 +44,10 @@ const a : Ta = @[(11, 22), (33, 44)] b : Tb = (@[55,66], @[77, 88]) -macro mA(data: static[Ta]): stmt = +macro mA(data: static[Ta]) = echo "AST a \n", repr(data) -macro mB(data: static[Tb]): stmt = +macro mB(data: static[Tb]) = echo "AST b \n", repr(data) echo data.e[0] @@ -57,13 +57,13 @@ mB(b) type Foo[N: static[int], Z: static[string]] = object -macro staticIntMacro(f: static[int]): stmt = echo f +macro staticIntMacro(f: static[int]) = echo f staticIntMacro 10 var x: Foo[20, "Test"] -macro genericMacro[N; Z: static[string]](f: Foo[N, Z], ll = 3, zz = 12): stmt = +macro genericMacro[N; Z: static[string]](f: Foo[N, Z], ll = 3, zz = 12) = echo N, Z genericMacro x diff --git a/tests/metatype/tstaticparams.nim b/tests/metatype/tstaticparams.nim index 69b62e4a6..ad6aa6589 100644 --- a/tests/metatype/tstaticparams.nim +++ b/tests/metatype/tstaticparams.nim @@ -74,7 +74,7 @@ matrix_2(tmat, ar2) matrix_3(tmat, ar1) matrix_4(tmat, ar2) -template reject(x): stmt = +template reject(x): untyped = static: assert(not compiles(x)) # test with arrays of wrong size diff --git a/tests/metatype/ttypedesc1.nim b/tests/metatype/ttypedesc1.nim index d78c62a94..e9eee581f 100644 --- a/tests/metatype/ttypedesc1.nim +++ b/tests/metatype/ttypedesc1.nim @@ -18,7 +18,7 @@ proc foo(T: typedesc[int or bool]): string = a = 10 result = "int or bool " & ($a) -template foo(T: typedesc[seq]): expr = "seq" +template foo(T: typedesc[seq]): string = "seq" test "types can be used as proc params": # XXX: `check` needs to know that TFoo[int, float] is a type and diff --git a/tests/metatype/ttypedesc2.nim b/tests/metatype/ttypedesc2.nim index e576ec91a..7650a6f6b 100644 --- a/tests/metatype/ttypedesc2.nim +++ b/tests/metatype/ttypedesc2.nim @@ -18,11 +18,10 @@ when true: uoffset_t* = uint32 FlatBufferBuilder* = object - uarray* {.unchecked.} [T] = array [0..0, T] Array* [T] = object o*: uoffset_t len*: int - data*: ptr uarray[T] + data*: ptr UncheckedArray[T] proc ca* (fbb: ptr FlatBufferBuilder, T: typedesc, len: int): Array[T] {.noinit.} = result.len = len diff --git a/tests/metatype/tymatrix.nim b/tests/metatype/tymatrix.nim index 7d3d52f85..14c4d8c88 100644 --- a/tests/metatype/tymatrix.nim +++ b/tests/metatype/tymatrix.nim @@ -1,6 +1,6 @@ import typetraits -template reject(e: expr) = +template reject(e) = static: assert(not compiles(e)) type diff --git a/tests/method/tmapper.nim b/tests/method/tmapper.nim index 0008d9033..a5d03f700 100644 --- a/tests/method/tmapper.nim +++ b/tests/method/tmapper.nim @@ -1,5 +1,5 @@ discard """ - errormsg: "invalid declaration order; cannot attach 'step' to method defined here: tmapper.nim(22,7)" + errormsg: "invalid declaration order; cannot attach 'step' to method defined here: tmapper.nim(22, 7)" line: 25 """ diff --git a/tests/misc/thallo.nim b/tests/misc/thallo.nim index 17e955f03..17e6089ed 100644 --- a/tests/misc/thallo.nim +++ b/tests/misc/thallo.nim @@ -15,7 +15,7 @@ proc fac[T](x: T): T = if x <= 1: return 1 else: return x.`*`(fac(x-1)) -macro macrotest(n: expr): stmt {.immediate.} = +macro macrotest(n: varargs[untyped]): untyped = let n = callsite() expectKind(n, nnkCall) expectMinLen(n, 2) @@ -24,7 +24,7 @@ macro macrotest(n: expr): stmt {.immediate.} = result.add(newCall("write", n[1], n[i])) result.add(newCall("writeLine", n[1], newStrLitNode(""))) -macro debug(n: expr): stmt {.immediate.} = +macro debug(n: untyped): untyped {.immediate.} = let n = callsite() result = newNimNode(nnkStmtList, n) for i in 1..n.len-1: @@ -82,4 +82,3 @@ for i in 2..6: when isMainModule: {.hint: "this is the main file".} - diff --git a/tests/misc/tints.nim b/tests/misc/tints.nim index 5bfb8a17c..d5374a543 100644 --- a/tests/misc/tints.nim +++ b/tests/misc/tints.nim @@ -8,7 +8,7 @@ Success''' var testNumber = 0 -template test(opr, a, b, c: expr): stmt {.immediate.} = +template test(opr, a, b, c: untyped): untyped = # test the expression at compile and runtime block: const constExpr = opr(a, b) diff --git a/tests/misc/tsimplesort.nim b/tests/misc/tsimplesort.nim index 9c6ad1207..3115863d5 100644 --- a/tests/misc/tsimplesort.nim +++ b/tests/misc/tsimplesort.nim @@ -118,7 +118,7 @@ proc toTable*[A, B](pairs: openarray[tuple[key: A, result = initTable[A, B](nextPowerOfTwo(pairs.len+10)) for key, val in items(pairs): result[key] = val -template dollarImpl(): stmt = +template dollarImpl(): typed = if t.len == 0: result = "{:}" else: @@ -305,5 +305,3 @@ proc countTableTest1 = countTableTest1() echo true - - diff --git a/tests/modules/tmismatchedvisibility.nim b/tests/modules/tmismatchedvisibility.nim index 91b639a27..2e8636d1e 100644 --- a/tests/modules/tmismatchedvisibility.nim +++ b/tests/modules/tmismatchedvisibility.nim @@ -1,6 +1,6 @@ discard """ line: 8 - errormsg: "public implementation 'tmismatchedvisibility.foo(a: int)[declared in tmismatchedvisibility.nim(6,5)]' has non-public forward declaration in " + errormsg: "public implementation 'tmismatchedvisibility.foo(a: int)[declared in tmismatchedvisibility.nim(6, 5)]' has non-public forward declaration in " """ proc foo(a: int): int diff --git a/tests/modules/treorder.nim b/tests/modules/treorder.nim new file mode 100644 index 000000000..25280c429 --- /dev/null +++ b/tests/modules/treorder.nim @@ -0,0 +1,46 @@ +discard """ + cmd: "nim -d:testdef $target $file" + output: '''works 34 +34 +defined +3''' +""" + +{.reorder: on.} +{.experimental.} + +{.push callconv: stdcall.} +proc bar(x: T) + +proc foo() = + bar(34) + whendep() + +proc foo(dummy: int) = echo dummy + +proc bar(x: T) = + echo "works ", x + foo(x) + +foo() + +type + T = int + +when defined(testdef): + proc whendep() = echo "defined" +else: + proc whendep() = echo "undefined" + +when not declared(goo): + proc goo(my, omy) = echo my + +when not declared(goo): + proc goo(my, omy) = echo omy + +using + my, omy: int + +goo(3, 4) + +{.pop.} diff --git a/tests/newconfig/tfoo.nims b/tests/newconfig/tfoo.nims index 8a709914f..8d0ed2c42 100644 --- a/tests/newconfig/tfoo.nims +++ b/tests/newconfig/tfoo.nims @@ -22,3 +22,5 @@ task default, "default target": --define: definedefine setCommand "c" +# bug #6327 +discard existsEnv("dummy") diff --git a/tests/nimble/nimbleDir/linkedPkgs/pkgA-0.1.0/pkgA.nimble-link b/tests/nimble/nimbleDir/linkedPkgs/pkgA-0.1.0/pkgA.nimble-link new file mode 100644 index 000000000..8dc825fc9 --- /dev/null +++ b/tests/nimble/nimbleDir/linkedPkgs/pkgA-0.1.0/pkgA.nimble-link @@ -0,0 +1,2 @@ +../../simplePkgs/pkgA-0.1.0/pkgA.nimble +../../simplePkgs/pkgA-0.1.0/ \ No newline at end of file diff --git a/tests/nimble/nimbleDir/linkedPkgs/pkgB-#head/pkgB.nimble-link b/tests/nimble/nimbleDir/linkedPkgs/pkgB-#head/pkgB.nimble-link new file mode 100644 index 000000000..a57a3cb66 --- /dev/null +++ b/tests/nimble/nimbleDir/linkedPkgs/pkgB-#head/pkgB.nimble-link @@ -0,0 +1,2 @@ +../../simplePkgs/pkgB-#head/pkgB.nimble +../../simplePkgs/pkgB-#head/ \ No newline at end of file diff --git a/tests/nimble/nimbleDir/linkedPkgs/pkgB-0.1.0/pkgB.nimble-link b/tests/nimble/nimbleDir/linkedPkgs/pkgB-0.1.0/pkgB.nimble-link new file mode 100644 index 000000000..9643c0fa0 --- /dev/null +++ b/tests/nimble/nimbleDir/linkedPkgs/pkgB-0.1.0/pkgB.nimble-link @@ -0,0 +1,2 @@ +../../simplePkgs/pkgB-0.1.0/pkgB.nimble +../../simplePkgs/pkgB-0.1.0/ \ No newline at end of file diff --git a/tests/nimble/nimbleDir/simplePkgs/pkgA-0.1.0/pkgA.nimble b/tests/nimble/nimbleDir/simplePkgs/pkgA-0.1.0/pkgA.nimble new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/nimble/nimbleDir/simplePkgs/pkgA-0.1.0/pkgA.nimble diff --git a/tests/nimble/nimbleDir/simplePkgs/pkgA-0.1.0/pkgA/module.nim b/tests/nimble/nimbleDir/simplePkgs/pkgA-0.1.0/pkgA/module.nim new file mode 100644 index 000000000..6cb3b77d9 --- /dev/null +++ b/tests/nimble/nimbleDir/simplePkgs/pkgA-0.1.0/pkgA/module.nim @@ -0,0 +1 @@ +proc pkgATest*(): int = 1 \ No newline at end of file diff --git a/tests/nimble/nimbleDir/simplePkgs/pkgB-#head/pkgB.nimble b/tests/nimble/nimbleDir/simplePkgs/pkgB-#head/pkgB.nimble new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/nimble/nimbleDir/simplePkgs/pkgB-#head/pkgB.nimble diff --git a/tests/nimble/nimbleDir/simplePkgs/pkgB-#head/pkgB/module.nim b/tests/nimble/nimbleDir/simplePkgs/pkgB-#head/pkgB/module.nim new file mode 100644 index 000000000..03d2298a2 --- /dev/null +++ b/tests/nimble/nimbleDir/simplePkgs/pkgB-#head/pkgB/module.nim @@ -0,0 +1 @@ +proc pkgBTest*(): int64 = 0xDEADBEEF \ No newline at end of file diff --git a/tests/nimble/nimbleDir/simplePkgs/pkgB-0.1.0/pkgB.nimble b/tests/nimble/nimbleDir/simplePkgs/pkgB-0.1.0/pkgB.nimble new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/nimble/nimbleDir/simplePkgs/pkgB-0.1.0/pkgB.nimble diff --git a/tests/nimble/nimbleDir/simplePkgs/pkgB-0.1.0/pkgB/module.nim b/tests/nimble/nimbleDir/simplePkgs/pkgB-0.1.0/pkgB/module.nim new file mode 100644 index 000000000..56ff64197 --- /dev/null +++ b/tests/nimble/nimbleDir/simplePkgs/pkgB-0.1.0/pkgB/module.nim @@ -0,0 +1 @@ +proc pkgBTest*(): int64 = 0 \ No newline at end of file diff --git a/tests/nimble/nimbleDir/simplePkgs/pkgC-#aa11/pkgC.nimble b/tests/nimble/nimbleDir/simplePkgs/pkgC-#aa11/pkgC.nimble new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/nimble/nimbleDir/simplePkgs/pkgC-#aa11/pkgC.nimble diff --git a/tests/nimble/nimbleDir/simplePkgs/pkgC-#aa11/pkgC/module.nim b/tests/nimble/nimbleDir/simplePkgs/pkgC-#aa11/pkgC/module.nim new file mode 100644 index 000000000..24a67bbe2 --- /dev/null +++ b/tests/nimble/nimbleDir/simplePkgs/pkgC-#aa11/pkgC/module.nim @@ -0,0 +1 @@ +proc pkgCTest*(): int64 = 1 \ No newline at end of file diff --git a/tests/nimble/nimbleDir/simplePkgs/pkgC-#head/pkgC.nimble b/tests/nimble/nimbleDir/simplePkgs/pkgC-#head/pkgC.nimble new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/nimble/nimbleDir/simplePkgs/pkgC-#head/pkgC.nimble diff --git a/tests/nimble/nimbleDir/simplePkgs/pkgC-#head/pkgC/module.nim b/tests/nimble/nimbleDir/simplePkgs/pkgC-#head/pkgC/module.nim new file mode 100644 index 000000000..2f243ad82 --- /dev/null +++ b/tests/nimble/nimbleDir/simplePkgs/pkgC-#head/pkgC/module.nim @@ -0,0 +1 @@ +proc pkgCTest*(): int64 = 0xDEADBEEF \ No newline at end of file diff --git a/tests/nimble/readme.md b/tests/nimble/readme.md new file mode 100644 index 000000000..10fd21a83 --- /dev/null +++ b/tests/nimble/readme.md @@ -0,0 +1,2 @@ +This directory contains tests for the --nimblePath feature. + diff --git a/tests/nimble/tnimblepath.nim b/tests/nimble/tnimblepath.nim new file mode 100644 index 000000000..6ba1be1d1 --- /dev/null +++ b/tests/nimble/tnimblepath.nim @@ -0,0 +1,11 @@ +discard """ + action: run + cmd: "nim $target --nimblePath:$fileDir/nimbleDir/simplePkgs $options $file" +""" +import pkgA/module as A +import pkgB/module as B +import pkgC/module as C + +doAssert pkgATest() == 1, "Simple pkgA-0.1.0 wasn't added to path correctly." +doAssert pkgBTest() == 0xDEADBEEF, "pkgB-#head wasn't picked over pkgB-0.1.0" +doAssert pkgCTest() == 0xDEADBEEF, "pkgC-#head wasn't picked over pkgC-#aa11" \ No newline at end of file diff --git a/tests/nimble/tnimblepathlink.nim b/tests/nimble/tnimblepathlink.nim new file mode 100644 index 000000000..5b2c7cb5b --- /dev/null +++ b/tests/nimble/tnimblepathlink.nim @@ -0,0 +1,9 @@ +discard """ + action: run + cmd: "nim $target --nimblePath:$fileDir/nimbleDir/linkedPkgs $options $file" +""" +import pkgA/module as A +import pkgB/module as B + +doAssert pkgATest() == 1, "Simple linked pkgA-0.1.0 wasn't added to path correctly." +doAssert pkgBTest() == 0xDEADBEEF, "linked pkgB-#head wasn't picked over pkgB-0.1.0" \ No newline at end of file diff --git a/tests/objects/tobjconstr.nim b/tests/objects/tobjconstr.nim index 226fe98f7..12478f621 100644 --- a/tests/objects/tobjconstr.nim +++ b/tests/objects/tobjconstr.nim @@ -8,7 +8,14 @@ discard """ (k: kindA, a: (x: abc, z: [1, 7, 3]), method: ()) (k: kindA, a: (x: abc, z: [1, 8, 3]), method: ()) (k: kindA, a: (x: abc, z: [1, 9, 3]), method: ()) -(k: kindA, a: (x: abc, z: [1, 10, 3]), method: ())''' +(k: kindA, a: (x: abc, z: [1, 10, 3]), method: ()) +(x: 123) +(x: 123) +(z: 89, y: 0, x: 128) +(y: 678, x: 123) +(y: 678, x: 123) +(y: 0, x: 123) +(y: 678, x: 123)''' """ type @@ -39,3 +46,32 @@ proc main() = main() +# bug #6294 +type + A = object of RootObj + x*: int + B = object of A + y*: int + BS = object of B + C = object of BS + z*: int +# inherited fields are ignored, so no fields are set +when true: + var + o: A + o = B(x: 123) + echo o + o = B(y: 678, x: 123) + echo o + +# inherited fields are ignored +echo C(x: 128, z: 89) # (y: 0, x: 0) +echo B(y: 678, x: 123) # (y: 678, x: 0) +echo B(x: 123, y: 678) # (y: 678, x: 0) + +when true: + # correct, both with `var` and `let`; + var b=B(x: 123) + echo b # (y: 0, x: 123) + b=B(y: 678, x: 123) + echo b # (y: 678, x: 123) diff --git a/tests/objects/tobject3.nim b/tests/objects/tobject3.nim index 15dd8ea24..a24a48c8b 100644 --- a/tests/objects/tobject3.nim +++ b/tests/objects/tobject3.nim @@ -1,3 +1,13 @@ +discard """ + output: '''TBar2 +TFoo +16 +12 +16 +12''' +""" + +## XXX this output needs to be adapated for VCC which produces different results. # It turned out that it's hard to generate correct for these two test cases at # the same time. @@ -57,3 +67,44 @@ var aa = makeWindow() thisCausesError(dd, aa) +# bug #4763 +type + testObject_1 = object + size: int32 + value: int64 + + testObject_2 {.packed.} = object + size: int32 + value: int64 + + testObject_3[T] = object + size: int32 + value: T + + testObject_4 {.packed.} [T] = object + size: int32 + value: T + +echo sizeof(testObject_1) +echo sizeof(testObject_2) +echo sizeof(testObject_3[int64]) +echo sizeof(testObject_4[int64]) + +# bug #5892 +type + Foo6 = distinct array[4, float32] + AnotherFoo = distinct array[4, float32] + + AbstractAnimationSampler* = ref object of RootObj + + AnimationSampler*[T] = ref object of AbstractAnimationSampler + sampleImpl: proc(s: AnimationSampler[T], p: float): T + + ArrayAnimationSampler*[T] = ref object of AnimationSampler[T] + +proc newArrayAnimationSampler*[T](): ArrayAnimationSampler[T] = + result.new() + result.sampleImpl = nil + +discard newArrayAnimationSampler[Foo6]() +discard newArrayAnimationSampler[AnotherFoo]() diff --git a/tests/objects/toop1.nim b/tests/objects/toop1.nim index 4727d146d..f4880e3c6 100644 --- a/tests/objects/toop1.nim +++ b/tests/objects/toop1.nim @@ -35,7 +35,7 @@ proc init(my: var TRectangle) = my.height = 10 my.draw = cast[proc (my: var TFigure) {.nimcall.}](drawRectangle) -macro `!` (n: expr): stmt {.immediate.} = +macro `!` (n: untyped): typed {.immediate.}= let n = callsite() result = newNimNode(nnkCall, n) var dot = newNimNode(nnkDotExpr, n) diff --git a/tests/osproc/tworkingdir.nim b/tests/osproc/tworkingdir.nim index 84ba3375c..eeed9240d 100644 --- a/tests/osproc/tworkingdir.nim +++ b/tests/osproc/tworkingdir.nim @@ -9,7 +9,11 @@ when defined(windows): discard else: let dir1 = getCurrentDir() - var process = startProcess("/usr/bin/env", "/usr/bin", ["true"]) + var process: Process + when defined(android): + process = startProcess("/system/bin/env", "/system/bin", ["true"]) + else: + process = startProcess("/usr/bin/env", "/usr/bin", ["true"]) let dir2 = getCurrentDir() discard process.waitForExit() process.close() diff --git a/tests/overload/tparams_after_varargs.nim b/tests/overload/tparams_after_varargs.nim index a93e280b9..ad8f19ad3 100644 --- a/tests/overload/tparams_after_varargs.nim +++ b/tests/overload/tparams_after_varargs.nim @@ -1,7 +1,8 @@ discard """ output: '''a 1 b 2 x @[3, 4, 5] y 6 z 7 yay -12''' +12 +''' """ proc test(a, b: int, x: varargs[int]; y, z: int) = @@ -9,9 +10,10 @@ proc test(a, b: int, x: varargs[int]; y, z: int) = test 1, 2, 3, 4, 5, 6, 7 -template takesBlock(a, b: int, x: varargs[expr]; blck: stmt) = +# XXX maybe this should also work with ``varargs[untyped]`` +template takesBlockA(a, b: untyped; x: varargs[typed]; blck: untyped): untyped = blck echo a, b -takesBlock 1, 2, "some", 0.90, "random stuff": +takesBlockA 1, 2, "some", 0.90, "random stuff": echo "yay" diff --git a/tests/overload/tspec.nim b/tests/overload/tspec.nim index f2002a390..a84bac244 100644 --- a/tests/overload/tspec.nim +++ b/tests/overload/tspec.nim @@ -71,7 +71,7 @@ var ri: ref int gen(ri) # "ref T" -template rem(x: expr) = discard +template rem(x) = discard #proc rem[T](x: T) = discard rem unresolvedExpression(undeclaredIdentifier) diff --git a/tests/overload/tstmtoverload.nim b/tests/overload/tstmtoverload.nim index 75584bcab..7c0194e60 100644 --- a/tests/overload/tstmtoverload.nim +++ b/tests/overload/tstmtoverload.nim @@ -2,17 +2,17 @@ # bug #2481 import math -template test(loopCount: int, extraI: int, testBody: stmt): stmt = +template test(loopCount: int, extraI: int, testBody: untyped): typed = block: for i in 0..loopCount-1: testBody echo "done extraI=", extraI -template test(loopCount: int, extraF: float, testBody: stmt): stmt = +template test(loopCount: int, extraF: float, testBody: untyped): typed = block: test(loopCount, round(extraF).int, testBody) -template test(loopCount: int, testBody: stmt): stmt = +template test(loopCount: int, testBody: untyped): typed = block: test(loopCount, 0, testBody) echo "done extraI passed 0" diff --git a/tests/parallel/tblocking_channel.nim b/tests/parallel/tblocking_channel.nim new file mode 100644 index 000000000..8b8b49454 --- /dev/null +++ b/tests/parallel/tblocking_channel.nim @@ -0,0 +1,37 @@ +discard """ +output: "" +""" +import threadpool, os + +var chan: Channel[int] + +chan.open(2) +chan.send(1) +chan.send(2) +doAssert(not chan.trySend(3)) # At this point chan is at max capacity + +proc receiver() = + doAssert(chan.recv() == 1) + doAssert(chan.recv() == 2) + doAssert(chan.recv() == 3) + doAssert(chan.recv() == 4) + doAssert(chan.recv() == 5) + +var msgSent = false + +proc emitter() = + chan.send(3) + msgSent = true + +spawn emitter() +# At this point emitter should be stuck in `send` +sleep(100) # Sleep a bit to ensure that it is still stuck +doAssert(not msgSent) + +spawn receiver() +sleep(100) # Sleep a bit to let receicer consume the messages +doAssert(msgSent) # Sender should be unblocked + +doAssert(chan.trySend(4)) +chan.send(5) +sync() diff --git a/tests/parallel/tconvexhull.nim b/tests/parallel/tconvexhull.nim index dffe5339b..c4990bf2d 100644 --- a/tests/parallel/tconvexhull.nim +++ b/tests/parallel/tconvexhull.nim @@ -20,10 +20,10 @@ proc cmpPoint(a, b: Point): int = if result == 0: result = cmp(a.y, b.y) -template cross[T](o, a, b: T): expr = +template cross[T](o, a, b: T): untyped = (a.x - o.x) * (b.y - o.y) - (a.y - o.y) * (b.x - o.x) -template pro(): expr = +template pro(): untyped = while lr1 > 0 and cross(result[lr1 - 1], result[lr1], p[i]) <= 0: discard result.pop lr1 -= 1 diff --git a/tests/parallel/tguard1.nim b/tests/parallel/tguard1.nim index 3e0c131c5..c7972d225 100644 --- a/tests/parallel/tguard1.nim +++ b/tests/parallel/tguard1.nim @@ -24,7 +24,7 @@ var c.i = 89 -template atomicRead(L, x): expr = +template atomicRead(L, x): untyped = {.locks: [L].}: x diff --git a/tests/parallel/tguard2.nim b/tests/parallel/tguard2.nim index b69ea3371..661893bb5 100644 --- a/tests/parallel/tguard2.nim +++ b/tests/parallel/tguard2.nim @@ -13,7 +13,7 @@ var c.i = 89 -template atomicRead(L, x): expr = +template atomicRead(L, x): untyped = {.locks: [L].}: x diff --git a/tests/parallel/tptr_to_ref.nim b/tests/parallel/tptr_to_ref.nim index 229c247ce..fee210dcd 100644 --- a/tests/parallel/tptr_to_ref.nim +++ b/tests/parallel/tptr_to_ref.nim @@ -14,7 +14,7 @@ type processes {.guard: lock.}: array[0..MAX_WORKERS-1, foreign ptr Process] # Hold a lock for a statement. -template hold(lock: Lock, body: stmt) = +template hold(lock: Lock, body: untyped) = lock.acquire defer: lock.release {.locks: [lock].}: diff --git a/tests/parser/toprprec.nim b/tests/parser/toprprec.nim index 2c22f5b80..1acd381e7 100644 --- a/tests/parser/toprprec.nim +++ b/tests/parser/toprprec.nim @@ -4,9 +4,11 @@ discard """ """ # Test operator precedence: -template `@` (x: expr): expr {.immediate.} = self.x -template `@!` (x: expr): expr {.immediate.} = x -template `===` (x: expr): expr {.immediate.} = x +template `@` (x: untyped): untyped {.immediate.} = + `self`.x + +template `@!` (x: untyped): untyped = x +template `===` (x: untyped): untyped = x type TO = object @@ -34,6 +36,3 @@ var s: TA assert init(s) == "4" echo "done" - - - diff --git a/tests/parser/tpostexprblocks.nim b/tests/parser/tpostexprblocks.nim index 85f2628bf..341ca737a 100644 --- a/tests/parser/tpostexprblocks.nim +++ b/tests/parser/tpostexprblocks.nim @@ -1,51 +1,59 @@ discard """ nimout: ''' StmtList - Ident !"foo" + Ident !"foo010" Call - Ident !"foo" + Ident !"foo020" Call - Ident !"foo" + Ident !"foo030" Ident !"x" Command - Ident !"foo" + Ident !"foo040" Ident !"x" Call - Ident !"foo" + Ident !"foo050" StmtList DiscardStmt Empty Call - Ident !"foo" + Ident !"foo060" StmtList DiscardStmt Empty Call - Ident !"foo" + Ident !"foo070" StrLit test StmtList DiscardStmt Empty Call - Ident !"foo" + Ident !"foo080" StrLit test StmtList DiscardStmt Empty Command - Ident !"foo" + Ident !"foo090" StrLit test StmtList DiscardStmt Empty Command - Ident !"foo" - StrLit test - StmtList - DiscardStmt - Empty + Ident !"foo100" + Call + StrLit test + StmtList + DiscardStmt + Empty Command - Ident !"foo" + Ident !"foo101" + Call + IntLit 10 + StmtList + DiscardStmt + Empty + Command + Ident !"foo110" IntLit 1 Par Infix @@ -56,18 +64,19 @@ StmtList DiscardStmt Empty Command - Ident !"foo" + Ident !"foo120" IntLit 1 - Par - Infix - Ident !"+" - IntLit 2 - IntLit 3 - StmtList - DiscardStmt - Empty + Call + Par + Infix + Ident !"+" + IntLit 2 + IntLit 3 + StmtList + DiscardStmt + Empty Call - Ident !"foo" + Ident !"foo130" Do Empty Empty @@ -84,7 +93,7 @@ StmtList DiscardStmt Empty Call - Ident !"foo" + Ident !"foo140" Do Empty Empty @@ -101,7 +110,7 @@ StmtList DiscardStmt Empty Call - Ident !"foo" + Ident !"foo150" Do Empty Empty @@ -118,25 +127,26 @@ StmtList DiscardStmt Empty Command - Ident !"foo" - Ident !"x" - Do - Empty - Empty - Empty - FormalParams + Ident !"foo160" + Call + Ident !"x" + Do Empty - IdentDefs - Ident !"y" - Empty - Empty - Empty - Empty - StmtList - DiscardStmt + Empty + Empty + FormalParams Empty + IdentDefs + Ident !"y" + Empty + Empty + Empty + Empty + StmtList + DiscardStmt + Empty Call - Ident !"foo" + Ident !"foo170" StmtList DiscardStmt Empty @@ -145,7 +155,7 @@ StmtList DiscardStmt Empty Call - Ident !"foo" + Ident !"foo180" StmtList DiscardStmt Empty @@ -157,62 +167,63 @@ StmtList DiscardStmt Empty Command - Ident !"foo" - Ident !"x" - Do - Empty - Empty - Empty - FormalParams + Ident !"foo190" + Call + Ident !"x" + Do Empty - IdentDefs - Ident !"y" - Empty - Empty - Empty - Empty - StmtList - DiscardStmt - Empty - Do - Empty - Empty - Empty - FormalParams - Ident !"int" - IdentDefs - Ident !"z" - Empty - Empty - Empty - Empty - StmtList - DiscardStmt + Empty + Empty + FormalParams Empty - Do - Empty - Empty - Empty - FormalParams - Ident !"int" - IdentDefs - Ident !"w" + IdentDefs + Ident !"y" + Empty + Empty + Empty + Empty + StmtList + DiscardStmt + Empty + Do + Empty + Empty + Empty + FormalParams Ident !"int" - Empty - Empty - Empty - StmtList - DiscardStmt - Empty - StmtList - DiscardStmt + IdentDefs + Ident !"z" + Empty + Empty Empty - Else + Empty + StmtList + DiscardStmt + Empty + Do + Empty + Empty + Empty + FormalParams + Ident !"int" + IdentDefs + Ident !"w" + Ident !"int" + Empty + Empty + Empty + StmtList + DiscardStmt + Empty StmtList DiscardStmt Empty + Else + StmtList + DiscardStmt + Empty Call - Ident !"foo" + Ident !"foo200" Ident !"x" Call Ident !"bar" @@ -227,33 +238,33 @@ StmtList IdentDefs Ident !"a" Empty - Ident !"foo" + Ident !"foo210" VarSection IdentDefs Ident !"a" Empty Call - Ident !"foo" + Ident !"foo220" VarSection IdentDefs Ident !"a" Empty Call - Ident !"foo" + Ident !"foo230" Ident !"x" VarSection IdentDefs Ident !"a" Empty Command - Ident !"foo" + Ident !"foo240" Ident !"x" VarSection IdentDefs Ident !"a" Empty Call - Ident !"foo" + Ident !"foo250" StmtList DiscardStmt Empty @@ -262,7 +273,7 @@ StmtList Ident !"a" Empty Call - Ident !"foo" + Ident !"foo260" StmtList DiscardStmt Empty @@ -271,7 +282,7 @@ StmtList Ident !"a" Empty Call - Ident !"foo" + Ident !"foo270" StmtList DiscardStmt Empty @@ -284,62 +295,63 @@ StmtList Ident !"a" Empty Command - Ident !"foo" - Ident !"x" - Do - Empty - Empty - Empty - FormalParams + Ident !"foo280" + Call + Ident !"x" + Do Empty - IdentDefs - Ident !"y" - Empty - Empty - Empty - Empty - StmtList - DiscardStmt - Empty - Else - StmtList - DiscardStmt + Empty + Empty + FormalParams Empty + IdentDefs + Ident !"y" + Empty + Empty + Empty + Empty + StmtList + DiscardStmt + Empty + Else + StmtList + DiscardStmt + Empty Asgn Ident !"a" - Ident !"foo" + Ident !"foo290" Asgn Ident !"a" Call - Ident !"foo" + Ident !"foo300" Asgn Ident !"a" Call - Ident !"foo" + Ident !"foo310" Ident !"x" Asgn Ident !"a" Command - Ident !"foo" + Ident !"foo320" Ident !"x" Asgn Ident !"a" Call - Ident !"foo" + Ident !"foo330" StmtList DiscardStmt Empty Asgn Ident !"a" Call - Ident !"foo" + Ident !"foo340" StmtList DiscardStmt Empty Asgn Ident !"a" Call - Ident !"foo" + Ident !"foo350" StmtList DiscardStmt Empty @@ -350,30 +362,42 @@ StmtList Asgn Ident !"a" Command - Ident !"foo" - Ident !"x" - Do - Empty - Empty - Empty - FormalParams + Ident !"foo360" + Call + DotExpr + Ident !"x" + Ident !"bar" + Do Empty - IdentDefs - Ident !"y" - Empty - Empty - Empty - Empty - StmtList - DiscardStmt - Empty - Else - StmtList - DiscardStmt + Empty + Empty + FormalParams Empty + IdentDefs + Ident !"y" + Empty + Empty + Empty + Empty + StmtList + DiscardStmt + Empty + Else + StmtList + DiscardStmt + Empty + Command + DotExpr + Ident !"foo370" + Ident !"add" + Call + Ident !"quote" + StmtList + DiscardStmt + Empty Call DotExpr - Ident !"result" + Ident !"foo380" Ident !"add" BracketExpr Call @@ -389,62 +413,65 @@ import macros dumpTree: # simple calls - foo - foo() - foo(x) - foo x + foo010 + foo020() + foo030(x) + foo040 x + + foo050: + discard - foo: + foo060 do: discard - foo do: + foo070("test"): discard - foo("test"): + foo080("test") do: discard - foo("test") do: + foo090 "test": discard - foo "test": + foo100 "test" do: discard - foo "test" do: + foo101 10 do: discard # more complicated calls - foo 1, (2+3): + foo110 1, (2+3): discard - foo 1, (2+3) do: + foo120 1, (2+3) do: discard - foo do (x): + foo130 do (x): discard - foo do (x: int): + foo140 do (x: int): discard - foo do (x: int) -> int: + foo150 do (x: int) -> int: discard - foo x do (y): + foo160 x do (y): discard # extra blocks - foo: + foo170: discard else: discard - foo do: + foo180 do: discard do: discard else: discard - foo x do (y): + foo190 x do (y): discard do (z) -> int: discard @@ -456,58 +483,61 @@ dumpTree: discard # call with blocks as a param - foo(x, bar do: + foo200(x, bar do: discard else: discard ) # introduce a variable - var a = foo - var a = foo() - var a = foo(x) - var a = foo x + var a = foo210 + var a = foo220() + var a = foo230(x) + var a = foo240 x - var a = foo: + var a = foo250: discard - var a = foo do: + var a = foo260 do: discard - var a = foo do: + var a = foo270 do: discard else: discard - var a = foo x do (y): + var a = foo280 x do (y): discard else: discard # assignments - a = foo - a = foo() - a = foo(x) - a = foo x + a = foo290 + a = foo300() + a = foo310(x) + a = foo320 x - a = foo: + a = foo330: discard - a = foo do: + a = foo340 do: discard - a = foo do: + a = foo350 do: discard else: discard - a = foo x do (y): + a = foo360 x.bar do (y): discard else: discard + foo370.add quote do: + discard + # some edge cases - result.add((quote do: + foo380.add((quote do: discard )[0]) diff --git a/tests/parser/tstrongspaces.nim b/tests/parser/tstrongspaces.nim index cb0219976..adab7f709 100644 --- a/tests/parser/tstrongspaces.nim +++ b/tests/parser/tstrongspaces.nim @@ -40,9 +40,9 @@ echo $foo echo (1, 2, 2) -template `&`(a, b: int): expr = a and b -template `|`(a, b: int): expr = a - b -template `++`(a, b: int): expr = a + b == 8009 +template `&`(a, b: int): int = a and b +template `|`(a, b: int): int = a - b +template `++`(a, b: int): bool = a + b == 8009 when true: let b = 66 @@ -62,7 +62,7 @@ when true: echo booA == booB -template `|`(a, b): expr = (if a.len > 0: a else: b) +template `|`(a, b): untyped = (if a.len > 0: a else: b) const tester = "tester" @@ -74,7 +74,7 @@ echo "all"|tester & " " & args # Test arrow like operators. See also tests/macros/tclosuremacro.nim proc `+->`(a, b: int): int = a + b*4 -template `===>`(a, b: int): expr = a - b shr 1 +template `===>`(a, b: int): int = a - b shr 1 echo 3 +-> 2 + 2 and 4 var arrowed = 3+->2 + 2 and 4 # arrowed = 4 diff --git a/tests/pragmas/tsym_as_pragma.nim b/tests/pragmas/tsym_as_pragma.nim index f6ba44dc9..788311244 100644 --- a/tests/pragmas/tsym_as_pragma.nim +++ b/tests/pragmas/tsym_as_pragma.nim @@ -1,7 +1,7 @@ # bug #3171 -template newDataWindow(): stmt = +template newDataWindow(): untyped = let eventClosure = proc (closure: pointer): bool {.closure, cdecl.} = discard diff --git a/tests/pragmas/tused.nim b/tests/pragmas/tused.nim index 389863aef..83c62b7bb 100644 --- a/tests/pragmas/tused.nim +++ b/tests/pragmas/tused.nim @@ -1,7 +1,7 @@ discard """ nimout: ''' compile start -tused.nim(15, 8) Hint: 'tused.echoSub(a: int, b: int)[declared in tused.nim(15,7)]' is declared but not used [XDeclaredButNotUsed] +tused.nim(15, 8) Hint: 'tused.echoSub(a: int, b: int)[declared in tused.nim(15, 7)]' is declared but not used [XDeclaredButNotUsed] compile end''' output: "8\n8" """ diff --git a/tests/range/compilehelpers.nim b/tests/range/compilehelpers.nim index cb26ca5b5..08f97a5bf 100644 --- a/tests/range/compilehelpers.nim +++ b/tests/range/compilehelpers.nim @@ -1,6 +1,5 @@ -template accept(e: expr) = +template accept(e) = static: assert(compiles(e)) -template reject(e: expr) = +template reject(e) = static: assert(not compiles(e)) - diff --git a/tests/readme.md b/tests/readme.md new file mode 100644 index 000000000..34a2c4bfb --- /dev/null +++ b/tests/readme.md @@ -0,0 +1,62 @@ +This directory contains the test cases. + +Each test must have a filename of the form: ``t*.nim`` + +**Note:** Tests are only compiled by default. In order to get the tester to +execute the compiled binary, you need to specify a spec with an ``action`` key +(see below for details). + +# Specs + +Each test can contain a spec in a ``discard """ ... """`` block. + +**Check out the [``parseSpec`` procedure](https://github.com/nim-lang/Nim/blob/devel/tests/testament/specs.nim#L124) in the ``specs`` module for a full and reliable reference** + +## action + +Specifies what action this test should take. + +**Default: compile** + +Options: + +* ``compile`` - compiles the module and fails the test if compilations fails. +* ``run`` - compiles and runs the module, fails the test if compilation or + execution of test code fails. +* ``reject`` - compiles the module and fails the test if compilation succeeds. + +There are certain spec keys that imply ``run``, including ``output`` and +``outputsub``. + +## cmd + +Specifies the Nim command to use for compiling the test. + +There are a number of variables that are replaced in this spec option: + +* ``$target`` - the compilation target, e.g. ``c``. +* ``$options`` - the options for the compiler. +* ``$file`` - the filename of the test. +* ``$filedir`` - the directory of the test file. + +Example: + +```nim +discard """ + cmd: "nim $target --nimblePath:./nimbleDir/simplePkgs $options $file" +""" +``` + +# Categories + +Each folder under this directory represents a test category, which can be +tested by running `koch tests cat <category>`. + +The folder ``rodfiles`` contains special tests that test incremental +compilation via symbol files. + +The folder ``dll`` contains simple DLL tests. + +The folder ``realtimeGC`` contains a test for validating that the realtime GC +can run properly without linking against the nimrtl.dll/so. It includes a C +client and platform specific build files for manual compilation. diff --git a/tests/readme.txt b/tests/readme.txt deleted file mode 100644 index 0ff9e11c6..000000000 --- a/tests/readme.txt +++ /dev/null @@ -1,13 +0,0 @@ -This directory contains the test cases. -Each test must have a filename of the form: ``t*.nim`` - -Each test can contain a spec in a ``discard """"""`` block. - -The folder ``rodfiles`` contains special tests that test incremental -compilation via symbol files. - -The folder ``dll`` contains simple DLL tests. - -The folder ``realtimeGC`` contains a test for validating that the realtime GC -can run properly without linking against the nimrtl.dll/so. It includes a C -client and platform specific build files for manual compilation. diff --git a/tests/showoff/tdrdobbs_examples.nim b/tests/showoff/tdrdobbs_examples.nim index 78f711325..8687ee529 100644 --- a/tests/showoff/tdrdobbs_examples.nim +++ b/tests/showoff/tdrdobbs_examples.nim @@ -105,10 +105,10 @@ proc pat2kind(pattern: string): FormulaKind = import macros proc matchAgainst(n, pattern: NimNode): NimNode {.compileTime.} = - template `@`(current, field: expr): expr = + template `@`(current, field: untyped): untyped = newDotExpr(current, newIdentNode(astToStr(field))) - template `==@`(n, pattern: expr): expr = + template `==@`(n, pattern: untyped): untyped = newCall("==", n@kind, newIdentNode($pat2kind($pattern.ident))) case pattern.kind @@ -126,7 +126,7 @@ proc matchAgainst(n, pattern: NimNode): NimNode {.compileTime.} = else: error "invalid pattern" -macro `=~` (n: Formula, pattern: expr): bool = +macro `=~` (n: Formula, pattern: untyped): bool = result = matchAgainst(n, pattern) proc isPolyTerm2(n: Formula): bool = n =~ c * x^c diff --git a/tests/showoff/tformatopt.nim b/tests/showoff/tformatopt.nim index f33ed6921..6e790c38e 100644 --- a/tests/showoff/tformatopt.nim +++ b/tests/showoff/tformatopt.nim @@ -10,7 +10,7 @@ import macros proc invalidFormatString() = echo "invalidFormatString" -template formatImpl(handleChar: expr) = +template formatImpl(handleChar: untyped) = var i = 0 while i < f.len: if f[i] == '$': @@ -29,11 +29,11 @@ template formatImpl(handleChar: expr) = i += 1 proc `%`*(f: string, a: openArray[string]): string = - template identity(x: expr): expr = x + template identity(x: untyped): untyped = x result = "" formatImpl(identity) -macro optFormat{`%`(f, a)}(f: string{lit}, a: openArray[string]): expr = +macro optFormat{`%`(f, a)}(f: string{lit}, a: openArray[string]): untyped = result = newNimNode(nnkBracket) let f = f.strVal formatImpl(newLit) diff --git a/tests/showoff/thtml1.nim b/tests/showoff/thtml1.nim index c7a083c21..fe0cd3b1e 100644 --- a/tests/showoff/thtml1.nim +++ b/tests/showoff/thtml1.nim @@ -2,7 +2,7 @@ discard """ output: "<br>" """ -template htmlTag(tag: expr) {.immediate.} = +template htmlTag(tag: untyped) = proc tag(): string = "<" & astToStr(tag) & ">" htmlTag(br) diff --git a/tests/showoff/thtml2.nim b/tests/showoff/thtml2.nim index faeb4e50d..dcf6534a5 100644 --- a/tests/showoff/thtml2.nim +++ b/tests/showoff/thtml2.nim @@ -4,20 +4,20 @@ discard """ import strutils -template html(name: expr, matter: stmt) {.immediate.} = +template html(name, matter: untyped) = proc name(): string = result = "<html>" matter result.add("</html>") -template nestedTag(tag: expr) {.immediate.} = - template tag(matter: stmt) {.immediate.} = +template nestedTag(tag: untyped) = + template tag(matter: untyped) = result.add("<" & astToStr(tag) & ">") matter result.add("</" & astToStr(tag) & ">") -template simpleTag(tag: expr) {.immediate.} = - template tag(matter: expr) {.immediate.} = +template simpleTag(tag: untyped) = + template tag(matter: untyped) = result.add("<$1>$2</$1>" % [astToStr(tag), matter]) nestedTag body diff --git a/tests/showoff/tonce.nim b/tests/showoff/tonce.nim index 6fc372e87..ed2684dcf 100644 --- a/tests/showoff/tonce.nim +++ b/tests/showoff/tonce.nim @@ -5,7 +5,7 @@ new instantiation some call of p''' """ -template once(body: stmt) = +template once(body) = var x {.global.} = false if not x: x = true diff --git a/tests/showoff/tquasiquote.nim b/tests/showoff/tquasiquote.nim index df7fccc33..404712a02 100644 --- a/tests/showoff/tquasiquote.nim +++ b/tests/showoff/tquasiquote.nim @@ -1,10 +1,10 @@ discard """ - outputsub: '''tquasiquote.nim(14,8): Check failed: 1 > 2''' + outputsub: '''tquasiquote.nim(14, 8): Check failed: 1 > 2''' """ import macros -macro check(ex: expr): stmt = +macro check(ex: untyped): untyped = var info = ex.lineInfo var expString = ex.toStrLit result = quote do: diff --git a/tests/specialops/tdotops.nim b/tests/specialops/tdotops.nim index ce5b3942d..bca949922 100644 --- a/tests/specialops/tdotops.nim +++ b/tests/specialops/tdotops.nim @@ -31,7 +31,7 @@ proc `.=`(x: var T1, f: string{lit}, v: int) = echo "assigning ", f, " = ", v x.x = v -template `.()`(x: T1, f: string, args: varargs[expr]): string = +template `.()`(x: T1, f: string, args: varargs[typed]): string = echo "call to ", f "dot call" @@ -63,4 +63,3 @@ echo tt.c(10) assert(not compiles(tt.d("x"))) assert(not compiles(tt.d(1, 2))) - diff --git a/tests/stdlib/tlocks.nim b/tests/stdlib/tlocks.nim new file mode 100644 index 000000000..e567cfde8 --- /dev/null +++ b/tests/stdlib/tlocks.nim @@ -0,0 +1,10 @@ +discard """ + output: '''3''' + cmd: "nim $target --threads:on $options $file" +""" + +#bug #6049 +import uselocks + +var m = createMyType[int]() +echo $m.use() diff --git a/tests/stdlib/tmarshal.nim b/tests/stdlib/tmarshal.nim index 6a53a2964..434caa281 100644 --- a/tests/stdlib/tmarshal.nim +++ b/tests/stdlib/tmarshal.nim @@ -9,7 +9,7 @@ omega 200 import marshal -template testit(x: expr) = discard $$to[type(x)]($$x) +template testit(x) = discard $$to[type(x)]($$x) var x: array[0..4, array[0..4, string]] = [ ["test", "1", "2", "3", "4"], ["test", "1", "2", "3", "4"], diff --git a/tests/stdlib/tnre.nim b/tests/stdlib/tnre.nim index 030319ebf..fabbb69a8 100644 --- a/tests/stdlib/tnre.nim +++ b/tests/stdlib/tnre.nim @@ -20,12 +20,13 @@ discard """ [Suite] Misc tests''' """ + import nre -import nre.init -import nre.captures -import nre.find -import nre.split -import nre.match -import nre.replace -import nre.escape -import nre.misc +import nre/init +import nre/captures +import nre/find +import nre/split +import nre/match +import nre/replace +import nre/escape +import nre/misc diff --git a/tests/stdlib/tparsecfg.nim b/tests/stdlib/tparsecfg.nim new file mode 100644 index 000000000..1c214e5d2 --- /dev/null +++ b/tests/stdlib/tparsecfg.nim @@ -0,0 +1,23 @@ +discard """ + output: '''OK''' +""" + +#bug #6046 +import parsecfg + +var config = newConfig() +config.setSectionKey("foo","bar","-1") +config.setSectionKey("foo","foo","abc") +config.writeConfig("test.ini") + +# test.ini now contains +# [foo] +# bar=-1 +# foo=abc + +var config2 = loadConfig("test.ini") +let bar = config2.getSectionValue("foo","bar") +let foo = config2.getSectionValue("foo","foo") +assert(bar == "-1") +assert(foo == "abc") +echo "OK" diff --git a/tests/stdlib/tpegs.nim b/tests/stdlib/tpegs.nim index ec839e288..e2a5a1715 100644 --- a/tests/stdlib/tpegs.nim +++ b/tests/stdlib/tpegs.nim @@ -149,7 +149,7 @@ proc addChoice(dest: var TPeg, elem: TPeg) = else: add(dest, elem) else: add(dest, elem) -template multipleOp(k: TPegKind, localOpt: expr) = +template multipleOp(k: TPegKind, localOpt) = result.kind = k result.sons = @[] for x in items(a): @@ -350,32 +350,32 @@ proc newNonTerminal*(name: string, line, column: int): PNonTerminal {. result.line = line result.col = column -template letters*: expr = +template letters*: TPeg = ## expands to ``charset({'A'..'Z', 'a'..'z'})`` charset({'A'..'Z', 'a'..'z'}) -template digits*: expr = +template digits*: TPeg = ## expands to ``charset({'0'..'9'})`` charset({'0'..'9'}) -template whitespace*: expr = +template whitespace*: TPeg = ## expands to ``charset({' ', '\9'..'\13'})`` charset({' ', '\9'..'\13'}) -template identChars*: expr = +template identChars*: TPeg = ## expands to ``charset({'a'..'z', 'A'..'Z', '0'..'9', '_'})`` charset({'a'..'z', 'A'..'Z', '0'..'9', '_'}) -template identStartChars*: expr = +template identStartChars*: TPeg = ## expands to ``charset({'A'..'Z', 'a'..'z', '_'})`` charset({'a'..'z', 'A'..'Z', '_'}) -template ident*: expr = +template ident*: TPeg = ## same as ``[a-zA-Z_][a-zA-z_0-9]*``; standard identifier sequence(charset({'a'..'z', 'A'..'Z', '_'}), *charset({'a'..'z', 'A'..'Z', '0'..'9', '_'})) -template natural*: expr = +template natural*: TPeg = ## same as ``\d+`` +digits @@ -534,10 +534,10 @@ proc bounds*(c: TCaptures, when not useUnicode: type Rune = char - template fastRuneAt(s, i, ch: expr) = + template fastRuneAt(s, i, ch) = ch = s[i] inc(i) - template runeLenAt(s, i: expr): expr = 1 + template runeLenAt(s, i): untyped = 1 proc isAlpha(a: char): bool {.inline.} = return a in {'a'..'z','A'..'Z'} proc isUpper(a: char): bool {.inline.} = return a in {'A'..'Z'} @@ -847,7 +847,7 @@ proc findAll*(s: string, pattern: TPeg, start = 0): seq[string] {. ## If it does not match, @[] is returned. accumulateResult(findAll(s, pattern, start)) -template `=~`*(s: string, pattern: TPeg): expr = +template `=~`*(s: string, pattern: TPeg): untyped = ## This calls ``match`` with an implicit declared ``matches`` array that ## can be used in the scope of the ``=~`` call: ## diff --git a/tests/stdlib/uselocks.nim b/tests/stdlib/uselocks.nim new file mode 100644 index 000000000..cde9641b2 --- /dev/null +++ b/tests/stdlib/uselocks.nim @@ -0,0 +1,11 @@ +import locks + +type MyType* [T] = object + lock: Lock + +proc createMyType*[T]: MyType[T] = + initLock(result.lock) + +proc use* (m: var MyType): int = + withLock m.lock: + result = 3 diff --git a/tests/template/annotate.nim b/tests/template/annotate.nim index 5f395557b..a7e2f8fdb 100644 --- a/tests/template/annotate.nim +++ b/tests/template/annotate.nim @@ -1,7 +1,7 @@ import macros, parseutils # Generate tags -macro make(names: openarray[expr]): stmt {.immediate.} = +macro make(names: untyped{nkBracket}): untyped = result = newStmtList() for i in 0 .. names.len-1: diff --git a/tests/template/mcan_access_hidden_field.nim b/tests/template/mcan_access_hidden_field.nim index bf3592701..2c0026ec1 100644 --- a/tests/template/mcan_access_hidden_field.nim +++ b/tests/template/mcan_access_hidden_field.nim @@ -5,5 +5,4 @@ type proc createFoo*(a, b: int): Foo = Foo(fooa: a, foob: b) -template geta*(f: Foo): expr = f.fooa - +template geta*(f: Foo): untyped = f.fooa diff --git a/tests/template/t2do.nim b/tests/template/t2do.nim index ec364c5f3..f5f6393dc 100644 --- a/tests/template/t2do.nim +++ b/tests/template/t2do.nim @@ -7,7 +7,7 @@ discard """ proc mpf_get_d(x: int): float = float(x) proc mpf_cmp_d(a: int; b: float): int = 0 -template toFloatHelper(result: expr; tooSmall, tooLarge: stmt) {.immediate.} = +template toFloatHelper(result, tooSmall, tooLarge: untyped) = result = mpf_get_d(a) if result == 0.0 and mpf_cmp_d(a,0.0) != 0: tooSmall diff --git a/tests/template/t_otemplates.nim b/tests/template/t_otemplates.nim index 6c419f72f..6597bd37a 100644 --- a/tests/template/t_otemplates.nim +++ b/tests/template/t_otemplates.nim @@ -126,7 +126,7 @@ iterator parse_compound_statements(value, identifier: string, index: int): strin ## and returns the initialization of each as an empty statement ## i.e. if x == 5 { ... } becomes if x == 5: nil. - template get_next_ident(expected): stmt = + template get_next_ident(expected) = var nextIdent: string discard value.parseWhile(nextIdent, {'$'} + identChars, i) @@ -316,10 +316,10 @@ proc parse_template(node: NimNode, value: string) = ## Nim code into the input `node` AST. var index = 0 while index < value.len and - parse_until_symbol(node, value, index): nil + parse_until_symbol(node, value, index): discard -macro tmpli*(body: expr): stmt = +macro tmpli*(body: untyped): untyped = result = newStmtList() result.add parseExpr("result = \"\"") @@ -330,7 +330,7 @@ macro tmpli*(body: expr): stmt = parse_template(result, reindent(value)) -macro tmpl*(body: expr): stmt = +macro tmpl*(body: untyped): untyped = result = newStmtList() var value = if body.kind in nnkStrLit..nnkTripleStrLit: body.strVal diff --git a/tests/template/tdefault_nil.nim b/tests/template/tdefault_nil.nim index 891166306..c5c372d9e 100644 --- a/tests/template/tdefault_nil.nim +++ b/tests/template/tdefault_nil.nim @@ -2,7 +2,7 @@ # bug #2629 import sequtils, os -template glob_rst(basedir: string = nil): expr = +template glob_rst(basedir: string = nil): untyped = if baseDir.isNil: to_seq(walk_files("*.rst")) else: diff --git a/tests/template/thygienictempl.nim b/tests/template/thygienictempl.nim index 5e4f534f8..de40450aa 100644 --- a/tests/template/thygienictempl.nim +++ b/tests/template/thygienictempl.nim @@ -2,7 +2,7 @@ var e = "abc" -raise newException(EIO, e & "ha!") +raise newException(IOError, e & "ha!") template t() = echo(foo) @@ -10,7 +10,7 @@ var foo = 12 t() -template test_in(a, b, c: expr): bool {.immediate, dirty.} = +template test_in(a, b, c: untyped): bool {.dirty.} = var result {.gensym.}: bool = false false diff --git a/tests/template/tissue909.nim b/tests/template/tissue909.nim index 5b57a3558..6786ff48c 100644 --- a/tests/template/tissue909.nim +++ b/tests/template/tissue909.nim @@ -8,7 +8,7 @@ template baz() = var y = foo discard y() -macro test(): stmt = +macro test(): untyped = result = getAst(baz()) echo(treeRepr(result)) diff --git a/tests/template/tissue993.nim b/tests/template/tissue993.nim index dae9df683..552890bb4 100644 --- a/tests/template/tissue993.nim +++ b/tests/template/tissue993.nim @@ -1,15 +1,15 @@ type PNode* = ref object of RootObj -template litNode (name, ty): stmt = +template litNode(name, ty) = type name* = ref object of PNode val*: ty litNode PIntNode, int import json -template withKey*(j: JsonNode; key: string; varname: expr; - body:stmt): stmt {.immediate.} = +template withKey*(j: JsonNode; key: string; varname, + body: untyped): typed = if j.hasKey(key): let varname{.inject.}= j[key] block: @@ -18,4 +18,3 @@ template withKey*(j: JsonNode; key: string; varname: expr; var j = parsejson("{\"zzz\":1}") withkey(j, "foo", x): echo(x) - diff --git a/tests/template/tit.nim b/tests/template/tit.nim index cf50d2f6f..76b1d151b 100644 --- a/tests/template/tit.nim +++ b/tests/template/tit.nim @@ -1,7 +1,7 @@ # bug #1337 -template someIt(a, pred: expr): expr = +template someIt(a, pred): untyped = var it {.inject.} = 0 pred diff --git a/tests/template/tparams_gensymed.nim b/tests/template/tparams_gensymed.nim index 568725fd4..3fb0dd4a5 100644 --- a/tests/template/tparams_gensymed.nim +++ b/tests/template/tparams_gensymed.nim @@ -43,7 +43,7 @@ template forStatic(index, slice, predicate: untyped) = block: const index = i predicate - template iterateStartingFrom(i: int): stmt = + template iterateStartingFrom(i: int) = when i <= b: iteration i iterateStartingFrom i + 1 diff --git a/tests/template/tprefer_immediate.nim b/tests/template/tprefer_immediate.nim index 578f447b0..3a4cfc07b 100644 --- a/tests/template/tprefer_immediate.nim +++ b/tests/template/tprefer_immediate.nim @@ -4,14 +4,12 @@ discard """ # Test that immediate templates are preferred over non-immediate templates -template foo(a, b: expr) = echo "foo expr" - +template foo(a, b: untyped) = echo "foo expr" template foo(a, b: int) = echo "foo int" template foo(a, b: float) = echo "foo float" template foo(a, b: string) = echo "foo string" -template foo(a, b: expr) {.immediate.} = echo "immediate" +template foo(a, b: untyped) {.immediate.} = echo "immediate" template foo(a, b: bool) = echo "foo bool" template foo(a, b: char) = echo "foo char" foo(undeclaredIdentifier, undeclaredIdentifier2) - diff --git a/tests/template/tscope.nim b/tests/template/tscope.nim index 2d5841af3..1eeebbdd4 100644 --- a/tests/template/tscope.nim +++ b/tests/template/tscope.nim @@ -3,7 +3,7 @@ discard """ """ var x = 1 -template quantity(): stmt {.immediate.} = +template quantity() = # Causes internal error in compiler/sem.nim proc unit*(x = 1.0): float = 12 # Throws the correct error: redefinition of 'x' diff --git a/tests/template/tstmt_semchecked_twice.nim b/tests/template/tstmt_semchecked_twice.nim index 05c16c3c9..c6463ae06 100644 --- a/tests/template/tstmt_semchecked_twice.nim +++ b/tests/template/tstmt_semchecked_twice.nim @@ -13,7 +13,7 @@ type Vector2[T] = T Pixels=int -template use*(fb: int, st: stmt) : stmt = +template use*(fb: int, st: untyped): untyped = echo "a ", $fb st echo "a ", $fb diff --git a/tests/template/tsymchoicefield.nim b/tests/template/tsymchoicefield.nim index ab05500bf..4483c2aa2 100644 --- a/tests/template/tsymchoicefield.nim +++ b/tests/template/tsymchoicefield.nim @@ -3,10 +3,9 @@ type Foo = object var f = Foo(len: 40) -template getLen(f: Foo): expr = f.len +template getLen(f: Foo): int = f.len echo f.getLen # This fails, because `len` gets the nkOpenSymChoice # treatment inside the template early pass and then # it can't be recognized as a field anymore - diff --git a/tests/template/ttempl3.nim b/tests/template/ttempl3.nim index 56daf9fe6..91d416c48 100644 --- a/tests/template/ttempl3.nim +++ b/tests/template/ttempl3.nim @@ -1,6 +1,6 @@ -template withOpenFile(f: expr, filename: string, mode: TFileMode, - actions: stmt): stmt {.immediate.} = +template withOpenFile(f: untyped, filename: string, mode: TFileMode, + actions: untyped): untyped = block: # test that 'f' is implicitly 'injecting': var f: TFile @@ -20,20 +20,20 @@ var myVar: array[0..1, int] # Test zero argument template: -template ha: expr = myVar[0] +template ha: untyped = myVar[0] ha = 1 echo(ha) # Test identifier generation: -template prefix(name: expr): expr {.immediate.} = `"hu" name` +template prefix(name): untyped = `"hu" name` var `hu "XYZ"` = "yay" echo prefix(XYZ) -template typedef(name: expr, typ: typeDesc) {.immediate, dirty.} = +template typedef(name: untyped, typ: typeDesc) {.immediate, dirty.} = type `T name`* = typ `P name`* = ref `T name` @@ -51,7 +51,7 @@ type proc initFoo(arg: int): Foo = result.arg = arg -template create(typ: typeDesc, arg: expr): expr = `init typ`(arg) +template create(typ: typeDesc, arg: untyped): untyped = `init typ`(arg) var ff = Foo.create(12) diff --git a/tests/template/ttempl4.nim b/tests/template/ttempl4.nim index 26c82e471..d1d26385f 100644 --- a/tests/template/ttempl4.nim +++ b/tests/template/ttempl4.nim @@ -1,8 +1,7 @@ -template `:=`(name, val: expr): stmt {.immediate.} = +template `:=`(name, val: untyped): typed = var name = val ha := 1 * 4 hu := "ta-da" == "ta-da" echo ha, hu - diff --git a/tests/template/ttempl5.nim b/tests/template/ttempl5.nim index a020a8e2c..fd3ea0cad 100644 --- a/tests/template/ttempl5.nim +++ b/tests/template/ttempl5.nim @@ -9,7 +9,7 @@ proc parse_to_close(value: string, index: int, open='(', close=')'): int = discard # Call parse_to_close -template get_next_ident: stmt = +template get_next_ident: typed = discard "{something}".parse_to_close(0, open = '{', close = '}') get_next_ident() @@ -19,11 +19,10 @@ get_next_ident() #bug #880 (also example in the manual!) -template typedef(name: expr, typ: typedesc) {.immediate.} = +template typedef(name: untyped, typ: typedesc) = type `T name`* {.inject.} = typ `P name`* {.inject.} = ref `T name` typedef(myint, int) var x: PMyInt - diff --git a/tests/template/twhen_gensym.nim b/tests/template/twhen_gensym.nim index d84ee6f03..f1a8d0eb7 100644 --- a/tests/template/twhen_gensym.nim +++ b/tests/template/twhen_gensym.nim @@ -3,7 +3,7 @@ discard """ """ # bug #2670 -template testTemplate(b: bool): stmt = +template testTemplate(b: bool): typed = when b: var a = "hi" else: diff --git a/tests/template/twrongmapit.nim b/tests/template/twrongmapit.nim index df695fcd6..cbc63b9cd 100644 --- a/tests/template/twrongmapit.nim +++ b/tests/template/twrongmapit.nim @@ -8,7 +8,7 @@ discard """ type Foo* {.pure, final.} = object elt: float -template defineOpAssign(T: expr, op: expr) {.immediate.} = +template defineOpAssign(T, op: untyped) {.immediate.} = proc op*(v: var T, w: T) {.inline.} = for i in 0..1: op(v.elt, w.elt) @@ -18,7 +18,7 @@ const ATTEMPT = 0 when ATTEMPT == 0: # FAILS: defining `/=` with template calling template # ERROR about sem.nim line 144 - template defineOpAssigns(T: expr) {.immediate.} = + template defineOpAssigns(T: untyped) = mixin `/=` defineOpAssign(T, `/=`) diff --git a/tests/template/twrongsymkind.nim b/tests/template/twrongsymkind.nim index be3d8c652..5fa618914 100644 --- a/tests/template/twrongsymkind.nim +++ b/tests/template/twrongsymkind.nim @@ -9,7 +9,7 @@ type MyData = object x: int -template newDataWindow(data: ref MyData): stmt = +template newDataWindow(data: ref MyData): untyped = proc testProc(data: ref MyData) = echo "Hello, ", data.x testProc(data) diff --git a/tests/template/utemplates.nim b/tests/template/utemplates.nim index 8b9ae5d26..199268046 100644 --- a/tests/template/utemplates.nim +++ b/tests/template/utemplates.nim @@ -1,32 +1,31 @@ import unittest -template t(a: int): expr = "int" -template t(a: string): expr = "string" +template t(a: int): string = "int" +template t(a: string): string = "string" test "templates can be overloaded": check t(10) == "int" check t("test") == "string" test "previous definitions can be further overloaded or hidden in local scopes": - template t(a: bool): expr = "bool" + template t(a: bool): string = "bool" check t(true) == "bool" check t(10) == "int" - template t(a: int): expr = "inner int" + template t(a: int): string = "inner int" check t(10) == "inner int" check t("test") == "string" test "templates can be redefined multiple times": - template customAssert(cond: bool, msg: string): stmt {.immediate, dirty.} = + template customAssert(cond: bool, msg: string): typed {.immediate, dirty.} = if not cond: fail(msg) - template assertion_failed(body: stmt) {.immediate, dirty.} = - template fail(msg: string): stmt = body + template assertion_failed(body: typed) {.immediate, dirty.} = + template fail(msg: string): typed = body assertion_failed: check msg == "first fail path" customAssert false, "first fail path" assertion_failed: check msg == "second fail path" customAssert false, "second fail path" - diff --git a/tests/testament/categories.nim b/tests/testament/categories.nim index 4ba07cd21..7b1dd0df0 100644 --- a/tests/testament/categories.nim +++ b/tests/testament/categories.nim @@ -139,7 +139,7 @@ proc gcTests(r: var TResults, cat: Category, options: string) = " -d:release --gc:markAndSweep", cat, actionRun) template test(filename: untyped) = testWithoutBoehm filename - when not defined(windows): + when not defined(windows) and not defined(android): # AR: cannot find any boehm.dll on the net, right now, so disabled # for windows: testSpec r, makeTest("tests/gc" / filename, options & diff --git a/tests/testament/tester.nim b/tests/testament/tester.nim index b83eb668a..e4bbc3a00 100644 --- a/tests/testament/tester.nim +++ b/tests/testament/tester.nim @@ -64,12 +64,22 @@ let var targets = {low(TTarget)..high(TTarget)} -proc normalizeMsg(s: string): string = s.strip.replace("\C\L", "\L") +proc normalizeMsg(s: string): string = + result = newStringOfCap(s.len+1) + for x in splitLines(s): + if result.len > 0: result.add '\L' + result.add x.strip + +proc getFileDir(filename: string): string = + result = filename.splitFile().dir + if not result.isAbsolute(): + result = getCurrentDir() / result proc callCompiler(cmdTemplate, filename, options: string, target: TTarget): TSpec = let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target], - "options", options, "file", filename.quoteShell]) + "options", options, "file", filename.quoteShell, + "filedir", filename.getFileDir()]) var p = startProcess(command=c[0], args=c[1.. ^1], options={poStdErrToStdOut, poUsePath}) let outp = p.outputStream @@ -114,7 +124,8 @@ proc callCompiler(cmdTemplate, filename, options: string, proc callCCompiler(cmdTemplate, filename, options: string, target: TTarget): TSpec = let c = parseCmdLine(cmdTemplate % ["target", targetToCmd[target], - "options", options, "file", filename.quoteShell]) + "options", options, "file", filename.quoteShell, + "filedir", filename.getFileDir()]) var p = startProcess(command="gcc", args=c[5.. ^1], options={poStdErrToStdOut, poUsePath}) let outp = p.outputStream diff --git a/tests/trmacros/targlist.nim b/tests/trmacros/targlist.nim index f9d2cb6c6..46235dab1 100644 --- a/tests/trmacros/targlist.nim +++ b/tests/trmacros/targlist.nim @@ -3,7 +3,7 @@ discard """ """ proc f(x: varargs[string, `$`]) = discard -template optF{f(x)}(x: varargs[expr]) = +template optF{f(x)}(x: varargs[untyped]) = writeLine(stdout, x) f 1, 2, false, 3, "ha" diff --git a/tests/trmacros/tcse.nim b/tests/trmacros/tcse.nim index 023a8f298..315570d8f 100644 --- a/tests/trmacros/tcse.nim +++ b/tests/trmacros/tcse.nim @@ -2,8 +2,8 @@ discard """ output: "4" """ -template cse{f(a, a, x)}(a: expr{(nkDotExpr|call|nkBracketExpr)&noSideEffect}, - f: expr, x: varargs[expr]): expr = +template cse{f(a, a, x)}(a: typed{(nkDotExpr|call|nkBracketExpr)&noSideEffect}, + f: typed, x: varargs[typed]): untyped = let aa = a f(aa, aa, x)+4 diff --git a/tests/trmacros/tmatrix.nim b/tests/trmacros/tmatrix.nim index f409434c5..a14ad2db0 100644 --- a/tests/trmacros/tmatrix.nim +++ b/tests/trmacros/tmatrix.nim @@ -15,7 +15,7 @@ proc `$`(a: TMat): string = result = $a.dummy proc mat21(): TMat = result.dummy = 21 -macro optOps{ (`+`|`-`|`*`) ** a }(a: TMat): expr = +macro optOps{ (`+`|`-`|`*`) ** a }(a: TMat): untyped = echo treeRepr(a) result = newCall(bindSym"mat21") diff --git a/tests/trmacros/tnoalias.nim b/tests/trmacros/tnoalias.nim index 1d5671362..ec12d4712 100644 --- a/tests/trmacros/tnoalias.nim +++ b/tests/trmacros/tnoalias.nim @@ -2,7 +2,7 @@ discard """ output: "23" """ -template optslice{a = b + c}(a: expr{noalias}, b, c: expr): stmt = +template optslice{a = b + c}(a: untyped{noalias}, b, c: untyped): typed = a = b inc a, c diff --git a/tests/trmacros/tnoalias2.nim b/tests/trmacros/tnoalias2.nim index 5a816acb9..9362e764f 100644 --- a/tests/trmacros/tnoalias2.nim +++ b/tests/trmacros/tnoalias2.nim @@ -3,7 +3,7 @@ discard """ """ # bug #206 -template optimizeOut{testFunc(a, b)}(a: int, b: int{alias}) : expr = 0 +template optimizeOut{testFunc(a, b)}(a: int, b: int{alias}): untyped = 0 proc testFunc(a, b: int): int = result = a + b var testVar = 1 diff --git a/tests/trmacros/tnoendlessrec.nim b/tests/trmacros/tnoendlessrec.nim index 53891bcc0..508770ca7 100644 --- a/tests/trmacros/tnoendlessrec.nim +++ b/tests/trmacros/tnoendlessrec.nim @@ -4,7 +4,7 @@ discard """ # test that an endless recursion is avoided: -template optLen{len(x)}(x: expr): expr = len(x) +template optLen{len(x)}(x: typed): int = len(x) var s = "lala" echo len(s) diff --git a/tests/trmacros/tor.nim b/tests/trmacros/tor.nim index 500851582..d698e928d 100644 --- a/tests/trmacros/tor.nim +++ b/tests/trmacros/tor.nim @@ -4,13 +4,13 @@ true 3''' """ -template arithOps: expr = (`+` | `-` | `*`) -template testOr{ (arithOps{f})(a, b) }(a, b, f: expr): expr = f(a+1, b) +template arithOps: untyped = (`+` | `-` | `*`) +template testOr{ (arithOps{f})(a, b) }(a, b, f: untyped): untyped = f(a+1, b) let xx = 10 echo 10*xx -template t{x = (~x){y} and (~x){z}}(x, y, z: bool): stmt = +template t{x = (~x){y} and (~x){z}}(x, y, z: bool): typed = x = y if x: x = z @@ -22,7 +22,7 @@ a = b and a echo a # bug #798 -template t012{(0|1|2){x}}(x: expr): expr = x+1 +template t012{(0|1|2){x}}(x: untyped): untyped = x+1 let z = 1 # outputs 3 thanks to fixpoint iteration: echo z diff --git a/tests/trmacros/tpartial.nim b/tests/trmacros/tpartial.nim index fdaa3414a..c636684d7 100644 --- a/tests/trmacros/tpartial.nim +++ b/tests/trmacros/tpartial.nim @@ -5,7 +5,7 @@ discard """ proc p(x, y: int; cond: bool): int = result = if cond: x + y else: x - y -template optP{p(x, y, true)}(x, y: expr): expr = x - y -template optP{p(x, y, false)}(x, y: expr): expr = x + y +template optP{p(x, y, true)}(x, y): untyped = x - y +template optP{p(x, y, false)}(x, y): untyped = x + y echo p(2, 4, true) diff --git a/tests/trmacros/tstar.nim b/tests/trmacros/tstar.nim index 536289ff0..86f698232 100644 --- a/tests/trmacros/tstar.nim +++ b/tests/trmacros/tstar.nim @@ -10,7 +10,7 @@ proc `&&`(s: varargs[string]): string = for i in 1..len(s)-1: result.add s[i] inc calls -template optConc{ `&&` * a }(a: string): expr = &&a +template optConc{ `&&` * a }(a: string): string = &&a let space = " " echo "my" && (space & "awe" && "some " ) && "concat" diff --git a/tests/trmacros/tstmtlist.nim b/tests/trmacros/tstmtlist.nim index 5202f778b..751acb79a 100644 --- a/tests/trmacros/tstmtlist.nim +++ b/tests/trmacros/tstmtlist.nim @@ -8,7 +8,7 @@ discard """ template optWrite{ write(f, x) ((write|writeLine){w})(f, y) -}(x, y: varargs[expr], f, w: expr) = +}(x, y: varargs[untyped], f, w: untyped) = w(f, "|", x, y, "|") if true: diff --git a/tests/tuples/tuple_with_nil.nim b/tests/tuples/tuple_with_nil.nim index 9b5d583d3..7f5a359f5 100644 --- a/tests/tuples/tuple_with_nil.nim +++ b/tests/tuples/tuple_with_nil.nim @@ -758,7 +758,7 @@ proc addfmtfmt(fmtstr: string; args: NimNode; retvar: NimNode): NimNode {.compil if arg.cnt == 0: warning("Argument " & $(i+1) & " `" & args[i].repr & "` is not used in format string") -macro addfmt(s: var string, fmtstr: string{lit}, args: varargs[expr]): expr = +macro addfmt(s: var string, fmtstr: string{lit}, args: varargs[typed]): untyped = ## The same as `s.add(fmtstr.fmt(args...))` but faster. result = addfmtfmt($fmtstr, args, s) diff --git a/tests/typerel/temptynode.nim b/tests/typerel/temptynode.nim index b32b16121..32148ce13 100644 --- a/tests/typerel/temptynode.nim +++ b/tests/typerel/temptynode.nim @@ -10,7 +10,7 @@ import macros proc blah(x: proc (a, b: int): int) = echo x(5, 5) -macro test(): stmt = +macro test(): untyped = result = newNimNode(nnkEmpty) blah(test()) diff --git a/tests/typerel/tsymchoice_for_expr.nim b/tests/typerel/tsymchoice_for_expr.nim index 4c1f52bef..394b22704 100644 --- a/tests/typerel/tsymchoice_for_expr.nim +++ b/tests/typerel/tsymchoice_for_expr.nim @@ -1,6 +1,6 @@ # bug #1988 -template t(e: expr) = discard +template t(e) = discard proc positive(x: int): int = +x proc negative(x: int): int = -x diff --git a/tests/typerel/tvarargsexpr.nim b/tests/typerel/tvarargsexpr.nim index c6a59fb20..092d50076 100644 --- a/tests/typerel/tvarargsexpr.nim +++ b/tests/typerel/tvarargsexpr.nim @@ -8,7 +8,7 @@ true''' import macros -macro thirteen(args: varargs[expr]): expr = +macro thirteen(args: varargs[untyped]): int = result = newIntLitNode(13) doAssert(13==thirteen([1,2])) # works @@ -22,7 +22,8 @@ echo "success" # bug #2545 import macros -macro test(e: varargs[untyped]): expr = bindSym"true" +macro test(e: varargs[untyped]): untyped = + bindSym"true" echo test(a) echo test(fake=90, arguments=80, also="false", possible=true) diff --git a/tests/types/taliasassignment.nim b/tests/types/taliasassignment.nim deleted file mode 100644 index bf4fe8520..000000000 --- a/tests/types/taliasassignment.nim +++ /dev/null @@ -1,50 +0,0 @@ -discard """ - output: '''19 -(c: 0) -(c: 13) -@[(c: 11)] -@[(c: 17)]''' -""" -# bug #5238 - -type - Rgba8 = object - c: int - BlenderRgb*[ColorT] = object - -template getColorType*[C](x: typedesc[BlenderRgb[C]]): typedesc = C - -type - ColorT = getColorType(BlenderRgb[int]) - -proc setColor(c: var ColorT) = - c = 19 - -var n: ColorT -n.setColor() -echo n - -type - ColorType = getColorType(BlenderRgb[Rgba8]) - -var x: ColorType -echo x - -proc setColor(c: var ColorType) = - c = Rgba8(c: 13) - -proc setColor(c: var seq[ColorType]) = - c[0] = Rgba8(c: 11) - -proc setColorArray(c: var openArray[ColorType]) = - c[0] = Rgba8(c: 17) - -x.setColor() -echo x - -var y = @[Rgba8(c:15)] -y.setColor() -echo y - -y.setColorArray() -echo y \ No newline at end of file diff --git a/tests/types/taliasbugs.nim b/tests/types/taliasbugs.nim new file mode 100644 index 000000000..57254760a --- /dev/null +++ b/tests/types/taliasbugs.nim @@ -0,0 +1,158 @@ +discard """ + msg: '''true +true +true +true +true +true''' + output: '''true +true +true +true +true +true +R +R +R +R +19 +(c: 0) +(c: 13) +@[(c: 11)] +@[(c: 17)] +100''' +""" + +# bug #5360 +import macros + +type + Order = enum + R + OrderAlias = Order + +template getOrderTypeA(): typedesc = Order +template getOrderTypeB(): typedesc = OrderAlias + +type + OrderR = getOrderTypeA() + OrderG = getOrderTypeB() + +macro typeRep(a, b: typed): untyped = + if sameType(a, b): + echo "true" + else: + echo "false" + +template test(a, b: typedesc) = + when a is b: + echo "true" + else: + echo "false" + +test(OrderAlias, Order) +test(OrderR, Order) +test(OrderG, Order) + +test(OrderR, OrderG) +test(OrderR, OrderAlias) +test(OrderG, OrderAlias) + +typeRep(OrderAlias.R, Order.R) # true +typeRep(OrderR.R, Order.R) # true +typeRep(OrderG.R, Order.R) # true + +typeRep(OrderR.R, OrderAlias.R) # true +typeRep(OrderG.R, OrderAlias.R) # true +typeRep(OrderR.R, OrderG.R) # true + +echo OrderR.R # R +echo OrderG.R # R +echo OrderAlias.R # R +echo Order.R # R + +# bug #5238 + +type + Rgba8 = object + c: int + BlenderRgb*[ColorT] = object + +template getColorType*[C](x: typedesc[BlenderRgb[C]]): typedesc = C + +type + ColorT = getColorType(BlenderRgb[int]) + +proc setColor(c: var ColorT) = + c = 19 + +var n: ColorT +n.setColor() +echo n + +type + ColorType = getColorType(BlenderRgb[Rgba8]) + +var x: ColorType +echo x + +proc setColor(c: var ColorType) = + c = Rgba8(c: 13) + +proc setColor(c: var seq[ColorType]) = + c[0] = Rgba8(c: 11) + +proc setColorArray(c: var openArray[ColorType]) = + c[0] = Rgba8(c: 17) + +x.setColor() +echo x + +var y = @[Rgba8(c:15)] +y.setColor() +echo y + +y.setColorArray() +echo y + +#bug #6016 +type + Onion {.union.} = object + field1: int + field2: uint64 + + Stroom = Onion + + PStroom = ptr Stroom + +proc pstruct(u: PStroom) = + echo u.field2 + +var oni = Onion(field1: 100) +pstruct(oni.addr) + + +# bug #4124 + +import sequtils + +type + Foo = distinct string + +var + foo: Foo + +type + Alias = (type(foo)) +var + a: Alias + +a = foo + +when true: + var xs = @[1,2,3] + + proc asFoo(i: string): Foo = + Foo(i) + + var xx = xs.mapIt(asFoo($(it + 5))) diff --git a/tests/types/taliasinequality.nim b/tests/types/taliasinequality.nim deleted file mode 100644 index f3ecd536a..000000000 --- a/tests/types/taliasinequality.nim +++ /dev/null @@ -1,66 +0,0 @@ -discard """ - msg: '''true -true -true -true -true -true''' - output: '''true -true -true -true -true -true -R -R -R -R''' -""" - -# bug #5360 -import macros - -type - Order = enum - R - OrderAlias = Order - -template getOrderTypeA(): typedesc = Order -template getOrderTypeB(): typedesc = OrderAlias - -type - OrderR = getOrderTypeA() - OrderG = getOrderTypeB() - -macro typeRep(a, b: typed): untyped = - if sameType(a, b): - echo "true" - else: - echo "false" - -template test(a, b: typedesc) = - when a is b: - echo "true" - else: - echo "false" - -test(OrderAlias, Order) -test(OrderR, Order) -test(OrderG, Order) - -test(OrderR, OrderG) -test(OrderR, OrderAlias) -test(OrderG, OrderAlias) - -typeRep(OrderAlias.R, Order.R) # true -typeRep(OrderR.R, Order.R) # true -typeRep(OrderG.R, Order.R) # true - -typeRep(OrderR.R, OrderAlias.R) # true -typeRep(OrderG.R, OrderAlias.R) # true -typeRep(OrderR.R, OrderG.R) # true - -echo OrderR.R # R -echo OrderG.R # R -echo OrderAlias.R # R -echo Order.R # R \ No newline at end of file diff --git a/tests/types/tauto_canbe_void.nim b/tests/types/tauto_canbe_void.nim index 60e83c510..fd42cb701 100644 --- a/tests/types/tauto_canbe_void.nim +++ b/tests/types/tauto_canbe_void.nim @@ -1,7 +1,7 @@ import future -template tempo(s: expr) = +template tempo(s) = s("arg") tempo((s: string)->auto => echo(s)) diff --git a/tests/types/tisopr.nim b/tests/types/tisopr.nim index 14999ebee..2f9dbf245 100644 --- a/tests/types/tisopr.nim +++ b/tests/types/tisopr.nim @@ -17,10 +17,10 @@ proc IsVoid[T](): string = const x = int is int echo x, " ", float is float, " ", float is string, " ", IsVoid[void]() -template yes(e: expr): stmt = +template yes(e): void = static: assert e -template no(e: expr): stmt = +template no(e): void = static: assert(not e) when false: diff --git a/tests/types/typeof_produces_alias.nim b/tests/types/typeof_produces_alias.nim deleted file mode 100644 index 44cb00c94..000000000 --- a/tests/types/typeof_produces_alias.nim +++ /dev/null @@ -1,25 +0,0 @@ - -# bug #4124 - -import sequtils - -type - Foo = distinct string - -var - foo: Foo - -type - Alias = (type(foo)) -var - a: Alias - -a = foo - -when true: - var xs = @[1,2,3] - - proc asFoo(i: string): Foo = - Foo(i) - - var xx = xs.mapIt(asFoo($(it + 5))) diff --git a/tests/untestable/readme.markdown b/tests/untestable/readme.markdown new file mode 100644 index 000000000..fcb7f4f28 --- /dev/null +++ b/tests/untestable/readme.markdown @@ -0,0 +1,2 @@ +This directory contains tests which are not automatically executed +for various reasons. Mainly due to dependencies on external services. \ No newline at end of file diff --git a/tests/usingstmt/tusingstatement.nim b/tests/usingstmt/tusingstatement.nim index 0d76b2423..8585bcc9e 100644 --- a/tests/usingstmt/tusingstatement.nim +++ b/tests/usingstmt/tusingstatement.nim @@ -12,7 +12,7 @@ import # Nim's destructors offer a mechanism for automatic # disposal of resources. # -macro autoClose(e: expr): stmt {.immediate.} = +macro autoClose(args: varargs[untyped]): untyped = let e = callsite() if e.len != 3: error "Using statement: unexpected number of arguments. Got " & @@ -85,5 +85,3 @@ proc use(r: var TResource) = autoClose(r = openResource("test")): use r - - diff --git a/tests/vm/tanonproc.nim b/tests/vm/tanonproc.nim index 474b768ca..c5cb57d75 100644 --- a/tests/vm/tanonproc.nim +++ b/tests/vm/tanonproc.nim @@ -42,7 +42,7 @@ proc getOrElse[T](o: Option[T], def: T): T = proc quoteStr(s: string): Option[string] = s.some.notEmpty.map(v => "`" & v & "`") -macro str(s: string): stmt = +macro str(s: string): typed = let x = s.strVal let y = quoteStr(x) let sn = newStrLitNode(y.getOrElse("NONE")) diff --git a/tests/vm/tasmparser.nim b/tests/vm/tasmparser.nim index fbacdbc87..d70c629b6 100644 --- a/tests/vm/tasmparser.nim +++ b/tests/vm/tasmparser.nim @@ -10,10 +10,10 @@ var cpp {.compileTime.} = "" token {.compileTime.} = "" -proc log (msg: string) {.compileTime.} = +proc log(msg: string) {.compileTime.} = echo msg -proc asmx64 () {.compileTime} = +proc asmx64() {.compileTime} = #log "code = $1" % code @@ -36,7 +36,7 @@ proc asmx64 () {.compileTime} = const end_or_symbol_or_comment_or_passthrough = symbolStart + end_or_comment + passthrough_start - proc abortAsmParse (err:string) = + proc abortAsmParse(err:string) = discard let codeLen = code.len @@ -49,17 +49,17 @@ proc asmx64 () {.compileTime} = var state:asmParseState = leading - proc checkEnd (err:string) = - let ch = code [start] - if int (ch) == 0: - abortAsmParse (err) + proc checkEnd(err:string) = + let ch = code[start] + if int(ch) == 0: + abortAsmParse(err) - proc get_passthrough () = + proc get_passthrough() = inc start let prev_start = start let prev_token = token - start += code.parseUntil (token, passthrough_end, start) - checkEnd ("Failed to find passthrough end delimiter from offset $1 for:$2\n$3" % [$prev_start, $(code [prev_start-prev_token.len..prev_start]), token[1..token.len-1]]) + start += code.parseUntil(token, passthrough_end, start) + checkEnd("Failed to find passthrough end delimiter from offset $1 for:$2\n$3" % [$prev_start, $(code[prev_start-prev_token.len..prev_start]), token[1..token.len-1]]) inc start cpp.add "`" cpp.add token @@ -67,27 +67,27 @@ proc asmx64 () {.compileTime} = var inparse = true - proc checkCmdEnd () = + proc checkCmdEnd() = if codeLen == start: state = endCmd inparse = false while inparse: - checkCmdEnd () + checkCmdEnd() - log ("state=$1 start=$2" % [$state, $start]) + log("state=$1 start=$2" % [$state, $start]) case state: of leading: echo "b100 ", start - start += code.skipWhile (leadingWhiteSpace, start) + start += code.skipWhile(leadingWhiteSpace, start) echo "b200 ", start - let ch = code [start] + let ch = code[start] if ch in endOfLine: - inc (line) + inc(line) #echo "c100 ", start, ' ', code - start += code.skipWhile (endOfline, start) + start += code.skipWhile(endOfline, start) #echo "c200 ", start, ' ', code continue elif ch in symbolStart: @@ -95,20 +95,20 @@ proc asmx64 () {.compileTime} = elif ch in eolComment: state = skipToEndOfLine elif ch in passthrough_start: - get_passthrough () + get_passthrough() echo "d100 ", start - start += code.parseUntil (token, end_or_symbol_or_comment_or_passthrough, start) + start += code.parseUntil(token, end_or_symbol_or_comment_or_passthrough, start) echo "d200 ", start cpp.add token state = mnemonic - elif int (ch) == 0: + elif int(ch) == 0: break else: - abortAsmParse ("after '$3' illegal character at offset $1: $2" % [$start, $(int (ch)), token]) + abortAsmParse("after '$3' illegal character at offset $1: $2" % [$start, $(int(ch)), token]) of mnemonic: echo "e100 ", start - start += code.parseWhile (token, symbol, start) + start += code.parseWhile(token, symbol, start) echo "e200 ", start cpp.add xp cpp.add token @@ -118,29 +118,29 @@ proc asmx64 () {.compileTime} = of betweenArguments: let tmp = start let rcode = code - start += rcode.parseUntil (token, end_or_symbol_or_comment_or_passthrough, tmp) + start += rcode.parseUntil(token, end_or_symbol_or_comment_or_passthrough, tmp) cpp.add token if codeLen <= start: state = endCmd continue - let ch = code [start] + let ch = code[start] if ch in passthrough_start: - get_passthrough () + get_passthrough() continue - if (ch in {'x', 'X'}) and ('0' == code [start-1]): - token = $(code [start]) + if(ch in {'x', 'X'}) and('0' == code[start-1]): + token = $(code[start]) cpp.add token inc start continue state = arguments of arguments: - if code [start] in end_or_comment: + if code[start] in end_or_comment: state = endCmd continue - start += code.parseWhile (token, symbol, start) + start += code.parseWhile(token, symbol, start) cpp.add xp cpp.add token state = betweenArguments @@ -151,21 +151,21 @@ proc asmx64 () {.compileTime} = of skipToEndOfLine: echo "a100 ", start - start += code.skipUntil (endOfLine, start) + start += code.skipUntil(endOfLine, start) echo "a200 ", start - start += code.skipWhile (endOfline, start) + start += code.skipWhile(endOfline, start) echo "a300 ", start inc line state = leading cpp.add asmx64post - echo ($cpp) + echo($cpp) -macro asmx64x (code_in:expr) : stmt = +macro asmx64x(code_in:untyped) : typed = code = $code_in - echo ("code.len = $1, code = >>>$2<<<" % [$code.len, code]) - asmx64 () + echo("code.len = $1, code = >>>$2<<<" % [$code.len, code]) + asmx64() discard result asmx64x """ diff --git a/tests/vm/tcomponent.nim b/tests/vm/tcomponent.nim index efeba2a6d..e7962e7ab 100644 --- a/tests/vm/tcomponent.nim +++ b/tests/vm/tcomponent.nim @@ -70,12 +70,12 @@ proc parse_component(body: NimNode): Component = result.procs_index.add(procdef.identifier.name) else: discard -macro component*(name: expr, body: stmt): stmt {.immediate.} = +macro component*(name, body: untyped): typed = let component = parse_component(body) registry.addComponent($name, component) parseStmt("discard") -macro component_builtins(body: stmt): stmt {.immediate.} = +macro component_builtins(body: untyped): typed = let builtin = parse_component(body) registry.field_index = builtin.field_index registry.procs_index = builtin.procs_index @@ -88,7 +88,7 @@ proc bind_methods*(component: var Component, identifier: Ident): seq[NimNode] = procdef.params.insert(this_field, 0) result.add(procdef.render()) -macro bind_components*(type_name, component_names: expr): stmt {.immediate.} = +macro bind_components*(type_name, component_names: untyped): typed = result = newStmtList() let identifier = newIdent(type_name) let components = newBracket(component_names) diff --git a/tests/vm/teval1.nim b/tests/vm/teval1.nim index 1d3a68a0d..0eaa050da 100644 --- a/tests/vm/teval1.nim +++ b/tests/vm/teval1.nim @@ -5,7 +5,7 @@ proc testProc: string {.compileTime.} = result = result & "" when true: - macro test(n: stmt): stmt {.immediate.} = + macro test(n: untyped): untyped = result = newNimNode(nnkStmtList) echo "#", testProc(), "#" test: @@ -20,5 +20,3 @@ echo "##", x, "##" static: var i, j: set[int8] = {} var k = i + j - - diff --git a/tests/vm/texcl.nim b/tests/vm/texcl.nim index 4ccfd6bfa..e23a423fe 100644 --- a/tests/vm/texcl.nim +++ b/tests/vm/texcl.nim @@ -15,13 +15,13 @@ proc initOpts(): set[nlOptions] = result.incl nloDebug result.incl nloNone result.excl nloDebug - + const cOpts = initOpts() -macro nlo(): stmt = +macro nlo(): typed = nlOpts.incl(nloNone) nlOpts.excl(nloDebug) result = newEmptyNode() nlo() -echo nloDebug in cOpts \ No newline at end of file +echo nloDebug in cOpts diff --git a/tests/vm/tmitems.nim b/tests/vm/tmitems.nim index 4ee225eed..a0e64d6aa 100644 --- a/tests/vm/tmitems.nim +++ b/tests/vm/tmitems.nim @@ -7,7 +7,7 @@ discard """ # bug #3731 var list {.compileTime.} = newSeq[int]() -macro calc*(): stmt {.immediate.} = +macro calc*(): typed = list.add(1) for c in list.mitems: c = 13 @@ -19,7 +19,7 @@ calc() # bug #3859 import macros -macro m: stmt = +macro m: typed = var s = newseq[NimNode](3) # var s: array[3,NimNode] # not working either for i in 0..<s.len: s[i] = newLit(3) # works @@ -29,3 +29,17 @@ macro m: stmt = result.add newCall(bindsym"echo", i) m() + +# bug 4741 & 5013 +proc test() = + var s = [("baz", 42), ("bath", 42)] + for i in s.mitems: + i[1] = 3 + doAssert(s == [("baz", 3), ("bath", 3)]) + +static: + test() + var s = [("baz", 42), ("bath", 42)] + for i in s.mitems: + i[1] = 3 + doAssert(s == [("baz", 3), ("bath", 3)]) diff --git a/tests/vm/tseq_badinit.nim b/tests/vm/tseq_badinit.nim new file mode 100644 index 000000000..15889d60e --- /dev/null +++ b/tests/vm/tseq_badinit.nim @@ -0,0 +1,58 @@ + +type + AObj = object + i: int + d: float + ATup = tuple + i: int + d: float + MyEnum = enum + E01, E02, E03 + Myrange = range[0..10] + + MyProc = proc (x: int): bool + MyInt = distinct int + MyAlias = MyInt + MySet = set[char] + MyArray = array[4, char] + MySeq = seq[string] + +template test(typename, default: untyped) = + proc `abc typename`(): seq[typename] = + result = newSeq[typename]() + result.add(default) + result.setLen(3) + for i in 0 .. <2: + result[i] = default + + const constval = `abc typename`() + doAssert(constval == `abc typename`()) + + proc `arr typename`(): array[4, typename] = + for i in 0 .. <2: + result[i] = default + const constarr = `arr typename`() + doAssert(constarr == `arr typename`()) + +proc even(x: int): bool = x mod 2 == 0 +proc `==`(x, y: MyInt): bool = ord(x) == ord(y) +proc `$`(x: MyInt): string = $ord(x) +proc `$`(x: proc): string = + if x.isNil: "(nil)" else: "funcptr" + +test(int, 0) +test(uint, 0) +test(float, 0.1) +test(char, '0') +test(bool, false) +test(uint8, 2) +test(string, "data") +test(MyProc, even) +test(MyEnum, E02) +test(AObj, AObj()) +test(ATup, (i:11, d:9.99)) +test(Myrange, 4) +test(MyInt, MyInt(4)) +test(MyAlias, MyAlias(4)) +test(MyArray, ['0','1','2','3']) +test(MySeq, @["data"]) diff --git a/tests/vm/tstaticprintseq.nim b/tests/vm/tstaticprintseq.nim index e4a6aa081..246a0211b 100644 --- a/tests/vm/tstaticprintseq.nim +++ b/tests/vm/tstaticprintseq.nim @@ -24,7 +24,7 @@ bb const s = @[1,2,3] -macro foo: stmt = +macro foo: typed = for e in s: echo e @@ -34,7 +34,7 @@ static: for e in s: echo e -macro bar(x: static[seq[int]]): stmt = +macro bar(x: static[seq[int]]): untyped = for e in x: echo e @@ -55,7 +55,7 @@ static: var m2: TData = data for x in m2.numbers: echo x -macro ff(d: static[TData]): stmt = +macro ff(d: static[TData]): typed = for x in d.letters: echo x diff --git a/tests/vm/tstringnil.nim b/tests/vm/tstringnil.nim index bb546b698..39e4040dc 100644 --- a/tests/vm/tstringnil.nim +++ b/tests/vm/tstringnil.nim @@ -41,7 +41,7 @@ proc buildSuiteContents(suiteName, suiteDesc, suiteBloc: NimNode): tuple[tests: return (tests: tests) -macro suite(suiteName, suiteDesc: expr, suiteBloc: stmt): stmt {.immediate.} = +macro suite(suiteName, suiteDesc, suiteBloc: untyped): typed = let contents = buildSuiteContents(suiteName, suiteDesc, suiteBloc) # Test above diff --git a/tests/vm/ttouintconv.nim b/tests/vm/ttouintconv.nim index cd25ffb00..5f8884e80 100644 --- a/tests/vm/ttouintconv.nim +++ b/tests/vm/ttouintconv.nim @@ -20,7 +20,7 @@ msg: ''' #bug #2514 -macro foo(): stmt = +macro foo(): typed = var x = 8'u8 var y = 9'u16 var z = 17'u32 @@ -57,21 +57,21 @@ macro foo(): stmt = var zz = 0x7FFFFFFF'u32 echo zz - -macro foo2(): stmt = + +macro foo2(): typed = var xx = 0x7FFFFFFFFFFFFFFF echo xx - + var yy = 0 echo yy - + var zz = 0x80'u8 echo zz - + var ww = -9 var vv = ww.uint var kk = vv.uint32 echo kk - + foo() foo2() diff --git a/tests/vm/twrongconst.nim b/tests/vm/twrongconst.nim index 424ed080e..a329cb578 100644 --- a/tests/vm/twrongconst.nim +++ b/tests/vm/twrongconst.nim @@ -4,6 +4,6 @@ discard """ """ var x: array[100, char] -template foo : expr = x[42] +template foo : char = x[42] const myConst = foo diff --git a/tests/vm/tzero_extend.nim b/tests/vm/tzero_extend.nim new file mode 100644 index 000000000..a79105531 --- /dev/null +++ b/tests/vm/tzero_extend.nim @@ -0,0 +1,44 @@ + +const RANGE = -384.. -127 + +proc get_values(): (seq[int8], seq[int16], seq[int32]) = + let i8 = -3'i8 + let i16 = -3'i16 + let i32 = -3'i32 + doAssert i8.ze == 0xFD + doAssert i8.ze64 == 0xFD + doAssert i16.ze == 0xFFFD + doAssert i16.ze64 == 0xFFFD + + result[0] = @[]; result[1] = @[]; result[2] = @[] + + for offset in RANGE: + let i8 = -(1 shl 9) + offset + let i16 = -(1 shl 17) + offset + let i32 = -(1 shl 33) + offset + + # higher bits are masked. these should be exactly equal to offset. + result[0].add i8.toU8 + result[1].add i16.toU16 + result[2].add i32.toU32 + + +# these values this computed by VM +const COMPILETIME_VALUES = get_values() + +# these values this computed by compiler +let RUNTIME_VALUES = get_values() + +template check_values(int_type: static[int]) = + var index = 0 + let cvalues = COMPILETIME_VALUES[int_type] + let rvalues = RUNTIME_VALUES[int_type] + for offset in RANGE: + let moffset = cast[type(rvalues[0])](offset) + doAssert(moffset == rvalues[index] and moffset == cvalues[index], + "expected: " & $moffset & " got runtime: " & $rvalues[index] & " && compiletime: " & $cvalues[index] ) + inc(index) + +check_values(0) # uint8 +check_values(1) # uint16 +check_values(2) # uint32 |