diff options
author | Zahary Karadjov <zahary@gmail.com> | 2013-12-29 17:21:00 +0200 |
---|---|---|
committer | Zahary Karadjov <zahary@gmail.com> | 2013-12-29 17:21:00 +0200 |
commit | afddae5aaf08a3a3357ec33d0bc82bdba0f5dc08 (patch) | |
tree | b6bd783f813797dcb5be4abaaade5ad599bb1c5c /tests/compile | |
parent | 437cfa73abd8fdf878cc2af2c44acbc4b6ec3a56 (diff) | |
parent | 72291875bf895e8e0d22ab3f375752417b07ed25 (diff) | |
download | Nim-afddae5aaf08a3a3357ec33d0bc82bdba0f5dc08.tar.gz |
Merge branch 'upstream' into devel
Conflicts: compiler/ccgutils.nim compiler/msgs.nim compiler/sem.nim compiler/semexprs.nim compiler/seminst.nim compiler/semmagic.nim compiler/semstmts.nim compiler/semtypes.nim compiler/semtypinst.nim compiler/sigmatch.nim compiler/types.nim compiler/vmgen.nim lib/core/macros.nim lib/system.nim tests/reject/tenummix.nim web/news.txt
Diffstat (limited to 'tests/compile')
-rw-r--r-- | tests/compile/tbindtypedesc.nim | 60 | ||||
-rw-r--r-- | tests/compile/tcompositetypeclasses.nim | 35 | ||||
-rw-r--r-- | tests/compile/tloops.nim | 128 |
3 files changed, 129 insertions, 94 deletions
diff --git a/tests/compile/tbindtypedesc.nim b/tests/compile/tbindtypedesc.nim index 4ebfd12bb..5ea8cf063 100644 --- a/tests/compile/tbindtypedesc.nim +++ b/tests/compile/tbindtypedesc.nim @@ -16,10 +16,10 @@ type TBar = tuple x, y: int -template good(e: expr) = +template accept(e: expr) = static: assert(compiles(e)) -template bad(e: expr) = +template reject(e: expr) = static: assert(not compiles(e)) proc genericParamRepeated[T: typedesc](a: T, b: T) = @@ -27,22 +27,22 @@ proc genericParamRepeated[T: typedesc](a: T, b: T) = echo a.name echo b.name -good(genericParamRepeated(int, int)) -good(genericParamRepeated(float, float)) +accept genericParamRepeated(int, int) +accept genericParamRepeated(float, float) -bad(genericParamRepeated(string, int)) -bad(genericParamRepeated(int, float)) +reject genericParamRepeated(string, int) +reject genericParamRepeated(int, float) proc genericParamOnce[T: typedesc](a, b: T) = static: echo a.name echo b.name -good(genericParamOnce(int, int)) -good(genericParamOnce(TFoo, TFoo)) +accept genericParamOnce(int, int) +accept genericParamOnce(TFoo, TFoo) -bad(genericParamOnce(string, int)) -bad(genericParamOnce(TFoo, float)) +reject genericParamOnce(string, int) +reject genericParamOnce(TFoo, float) type type1 = typedesc @@ -50,42 +50,42 @@ type proc typePairs(A, B: type1; C, D: type2) = nil -good(typePairs(int, int, TFoo, TFOO)) -good(typePairs(TBAR, TBar, TBAR, TBAR)) -good(typePairs(int, int, string, string)) +accept typePairs(int, int, TFoo, TFOO) +accept typePairs(TBAR, TBar, TBAR, TBAR) +accept typePairs(int, int, string, string) -bad(typePairs(TBAR, TBar, TBar, TFoo)) -bad(typePairs(string, int, TBAR, TBAR)) +reject typePairs(TBAR, TBar, TBar, TFoo) +reject typePairs(string, int, TBAR, TBAR) proc typePairs2[T: typedesc, U: typedesc](A, B: T; C, D: U) = nil -good(typePairs2(int, int, TFoo, TFOO)) -good(typePairs2(TBAR, TBar, TBAR, TBAR)) -good(typePairs2(int, int, string, string)) +accept typePairs2(int, int, TFoo, TFOO) +accept typePairs2(TBAR, TBar, TBAR, TBAR) +accept typePairs2(int, int, string, string) -bad(typePairs2(TBAR, TBar, TBar, TFoo)) -bad(typePairs2(string, int, TBAR, TBAR)) +reject typePairs2(TBAR, TBar, TBar, TFoo) +reject typePairs2(string, int, TBAR, TBAR) proc dontBind(a: typedesc, b: typedesc) = static: echo a.name echo b.name -good(dontBind(int, float)) -good(dontBind(TFoo, TFoo)) +accept dontBind(int, float) +accept dontBind(TFoo, TFoo) proc dontBind2(a, b: typedesc) = nil -good(dontBind2(int, float)) -good(dontBind2(TBar, int)) +accept dontBind2(int, float) +accept dontBind2(TBar, int) proc bindArg(T: typedesc, U: typedesc, a, b: T, c, d: U) = nil -good(bindArg(int, string, 10, 20, "test", "nest")) -good(bindArg(int, int, 10, 20, 30, 40)) +accept bindArg(int, string, 10, 20, "test", "nest") +accept bindArg(int, int, 10, 20, 30, 40) -bad(bindArg(int, string, 10, "test", "test", "nest")) -bad(bindArg(int, int, 10, 20, 30, "test")) -bad(bindArg(int, string, 10.0, 20, "test", "nest")) -bad(bindArg(int, string, "test", "nest", 10, 20)) +reject bindArg(int, string, 10, "test", "test", "nest") +reject bindArg(int, int, 10, 20, 30, "test") +reject bindArg(int, string, 10.0, 20, "test", "nest") +reject bindArg(int, string, "test", "nest", 10, 20) diff --git a/tests/compile/tcompositetypeclasses.nim b/tests/compile/tcompositetypeclasses.nim new file mode 100644 index 000000000..4ba92fed1 --- /dev/null +++ b/tests/compile/tcompositetypeclasses.nim @@ -0,0 +1,35 @@ +template accept(e) = + static: assert(compiles(e)) + +template reject(e) = + static: assert(not compiles(e)) + +type + TFoo[T, U] = tuple + x: T + y: U + + TBar[K] = TFoo[K, K] + + TUserClass = int|string + + TBaz = TBar[TUserClass] + +var + vfoo: TFoo[int, string] + vbar: TFoo[string, string] + vbaz: TFoo[int, int] + vnotbaz: TFoo[TObject, TObject] + +proc foo(x: TFoo) = echo "foo" +proc bar(x: TBar) = echo "bar" +proc baz(x: TBaz) = echo "baz" + +accept foo(vfoo) +accept bar(vbar) +accept baz(vbar) +accept baz(vbaz) + +reject baz(vnotbaz) +reject bar(vfoo) + diff --git a/tests/compile/tloops.nim b/tests/compile/tloops.nim index 2b1765b00..f6f939769 100644 --- a/tests/compile/tloops.nim +++ b/tests/compile/tloops.nim @@ -1,67 +1,67 @@ -# Test nested loops and some other things - -proc andTest() = - var a = 0 == 5 and 6 == 6 - -proc incx(x: var int) = # is built-in proc - x = x + 1 - -proc decx(x: var int) = - x = x - 1 - -proc First(y: var int) = - var x: int - i_ncx(x) - if x == 10: - y = 0 - else: - if x == 0: - incx(x) - else: - x=11 - -proc TestLoops() = - var i, j: int - while i >= 0: - if i mod 3 == 0: - break - i = i + 1 - while j == 13: - j = 13 - break - break - - while True: - break - - -proc Foo(n: int): int = - var - a, old: int - b, c: bool - F_irst(a) - if a == 10: - a = 30 - elif a == 11: - a = 22 - elif a == 12: - a = 23 - elif b: - old = 12 - else: - a = 40 - - # - b = false or 2 == 0 and 3 == 9 - a = 0 + 3 * 5 + 6 + 7 + +8 # 36 - while b: - a = a + 3 - a = a + 5 - write(stdout, "Hello!") - - -# We should come till here :-) -discard Foo(345) +# Test nested loops and some other things + +proc andTest() = + var a = 0 == 5 and 6 == 6 + +proc incx(x: var int) = # is built-in proc + x = x + 1 + +proc decx(x: var int) = + x = x - 1 + +proc First(y: var int) = + var x: int + i_ncx(x) + if x == 10: + y = 0 + else: + if x == 0: + incx(x) + else: + x=11 + +proc TestLoops() = + var i, j: int + while i >= 0: + if i mod 3 == 0: + break + i = i + 1 + while j == 13: + j = 13 + break + break + + while True: + break + + +proc Foo(n: int): int = + var + a, old: int + b, c: bool + F_irst(a) + if a == 10: + a = 30 + elif a == 11: + a = 22 + elif a == 12: + a = 23 + elif b: + old = 12 + else: + a = 40 + + # + b = false or 2 == 0 and 3 == 9 + a = 0 + 3 * 5 + 6 + 7 + +8 # 36 + while b: + a = a + 3 + a = a + 5 + write(stdout, "Hello!") + + +# We should come till here :-) +discard Foo(345) # test the new type symbol lookup feature: |