diff options
Diffstat (limited to 'tests/overload')
-rw-r--r-- | tests/overload/toverl2.nim | 6 | ||||
-rw-r--r-- | tests/overload/toverl3.nim | 6 | ||||
-rw-r--r-- | tests/overload/toverl4.nim | 2 | ||||
-rw-r--r-- | tests/overload/toverprc.nim | 2 | ||||
-rw-r--r-- | tests/overload/toverwr.nim | 26 | ||||
-rw-r--r-- | tests/overload/tspec.nim | 39 | ||||
-rw-r--r-- | tests/overload/tstmtoverload.nim | 38 |
7 files changed, 97 insertions, 22 deletions
diff --git a/tests/overload/toverl2.nim b/tests/overload/toverl2.nim index ea0249e9f..54714ac1b 100644 --- a/tests/overload/toverl2.nim +++ b/tests/overload/toverl2.nim @@ -9,9 +9,9 @@ import strutils proc toverl2(x: int): string = return $x proc toverl2(x: bool): string = return $x -iterator toverl2(x: int): int = +iterator toverl2(x: int): int = var res = 0 - while res < x: + while res < x: yield res inc(res) @@ -20,7 +20,7 @@ var stdout.write(pp(true)) -for x in toverl2(3): +for x in toverl2(3): stdout.write(toverl2(x)) block: diff --git a/tests/overload/toverl3.nim b/tests/overload/toverl3.nim index b3e0f2fa7..92cfc150d 100644 --- a/tests/overload/toverl3.nim +++ b/tests/overload/toverl3.nim @@ -4,8 +4,8 @@ discard """ tup1''' """ -# Tests more specific generic match: - +# Tests more specific generic match: + proc m[T](x: T) = echo "m2" proc m[T](x: var ref T) = echo "m1" @@ -15,6 +15,6 @@ proc tup[S, T](x: tuple[a: S, b: T]) = echo "tup2" var obj: ref int tu: tuple[a: int, b: ref bool] - + m(obj) tup(tu) diff --git a/tests/overload/toverl4.nim b/tests/overload/toverl4.nim index 6bb3a53d1..b63265bdf 100644 --- a/tests/overload/toverl4.nim +++ b/tests/overload/toverl4.nim @@ -74,4 +74,4 @@ proc add*[TKey, TData](root: var PElement[TKey, TData], key: TKey, data: TData) var tree = PElement[int, int](kind: ElementKind.inner, key: 0, left: nil, right: nil) let result = add(tree, 1, 1) -echo(result) \ No newline at end of file +echo(result) diff --git a/tests/overload/toverprc.nim b/tests/overload/toverprc.nim index 78831f744..112eae096 100644 --- a/tests/overload/toverprc.nim +++ b/tests/overload/toverprc.nim @@ -5,7 +5,7 @@ yay''' # Test overloading of procs when used as function pointers -import strutils +import strutils, sequtils proc parseInt(x: float): int {.noSideEffect.} = discard proc parseInt(x: bool): int {.noSideEffect.} = discard diff --git a/tests/overload/toverwr.nim b/tests/overload/toverwr.nim index 32d50faaa..5945a6149 100644 --- a/tests/overload/toverwr.nim +++ b/tests/overload/toverwr.nim @@ -1,13 +1,13 @@ -discard """ - file: "toverwr.nim" - output: "hello" -""" -# Test the overloading resolution in connection with a qualifier - -proc write(t: TFile, s: string) = - discard # a nop - -system.write(stdout, "hello") -#OUT hello - - +discard """ + file: "toverwr.nim" + output: "hello" +""" +# Test the overloading resolution in connection with a qualifier + +proc write(t: TFile, s: string) = + discard # a nop + +system.write(stdout, "hello") +#OUT hello + + diff --git a/tests/overload/tspec.nim b/tests/overload/tspec.nim index 685df503a..f2002a390 100644 --- a/tests/overload/tspec.nim +++ b/tests/overload/tspec.nim @@ -11,7 +11,10 @@ ref T 123 2 1 -@[123, 2, 1]''' +@[123, 2, 1] +Called! +merge with var +merge no var''' """ # Things that's even in the spec now! @@ -79,3 +82,37 @@ proc takeV[T](a: varargs[T]) = takeV([123, 2, 1]) # takeV's T is "int", not "array of int" echo(@[123, 2, 1]) + +# bug #2600 + +type + FutureBase* = ref object of RootObj ## Untyped future. + + Future*[T] = ref object of FutureBase ## Typed future. + value: T ## Stored value + + FutureVar*[T] = distinct Future[T] + +proc newFuture*[T](): Future[T] = + new(result) + +proc newFutureVar*[T](): FutureVar[T] = + result = FutureVar[T](newFuture[T]()) + +proc mget*[T](future: FutureVar[T]): var T = + Future[T](future).value + +proc reset*[T](future: FutureVar[T]) = + echo "Called!" + +proc merge[T](x: Future[T]) = echo "merge no var" +proc merge[T](x: var Future[T]) = echo "merge with var" + +when true: + var foo = newFutureVar[string]() + foo.mget() = "" + foo.mget.add("Foobar") + foo.reset() + var bar = newFuture[int]() + bar.merge # merge with var + merge(newFuture[int]()) # merge no var diff --git a/tests/overload/tstmtoverload.nim b/tests/overload/tstmtoverload.nim new file mode 100644 index 000000000..f1944b637 --- /dev/null +++ b/tests/overload/tstmtoverload.nim @@ -0,0 +1,38 @@ + +# bug #2481 +import math + +template test(loopCount: int, extraI: int, testBody: stmt): stmt = + block: + for i in 0..loopCount-1: + testBody + echo "done extraI=", extraI + +template test(loopCount: int, extraF: float, testBody: stmt): stmt = + block: + test(loopCount, round(extraF), testBody) + +template test(loopCount: int, testBody: stmt): stmt = + block: + test(loopCount, 0, testBody) + echo "done extraI passed 0" + +when isMainModule: + var + loops = 0 + + test 0, 0: + loops += 1 + echo "test 0 complete, loops=", loops + + test 1, 1.0: + loops += 1 + echo "test 1.0 complete, loops=", loops + + when true: + # when true we get the following compile time error: + # b.nim(35, 6) Error: expression 'loops += 1' has no type (or is ambiguous) + loops = 0 + test 2: + loops += 1 + echo "test no extra complete, loops=", loops |