diff options
author | cooldome <ariabushenko@gmail.com> | 2020-11-06 09:25:43 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-06 10:25:43 +0100 |
commit | cdd459dd60e7cf69868ac23e754e8047df6afddc (patch) | |
tree | 90fe3661366a470eccdc3f8b02738f3a1ac6fe80 /tests | |
parent | fa5f225efc7161110b0d4cf57e86646f2b0d97f8 (diff) | |
download | Nim-cdd459dd60e7cf69868ac23e754e8047df6afddc.tar.gz |
static[T] related fixes (#15853)
* close #9679 * close #7546 * close #9520 * close #6177
Diffstat (limited to 'tests')
-rw-r--r-- | tests/statictypes/tstatictypes.nim | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/tests/statictypes/tstatictypes.nim b/tests/statictypes/tstatictypes.nim index 50dc60e09..b5c45850a 100644 --- a/tests/statictypes/tstatictypes.nim +++ b/tests/statictypes/tstatictypes.nim @@ -10,6 +10,8 @@ b is 2 times a 17 ['\x00', '\x00', '\x00', '\x00'] heyho +Val1 +Val1 ''' """ @@ -239,3 +241,102 @@ let t = T[true](foo: "hey") let u = U[false](bar: "ho") echo t.foo, u.bar + +#------------------------------------------------------------------------------ +# issue #9679 + +discard """ + output: '''''' +""" +type + Foo*[T] = object + bar*: int + dummy: T + +proc initFoo(T: type, bar: int): Foo[T] = + result.bar = 1 + +proc fails[T](x: static Foo[T]) = # Change to non-static and it compiles + doAssert($x == "(bar: 1, dummy: 0)") + +block: + const foo = initFoo(int, 2) + fails(foo) + + +import macros, tables + +var foo{.compileTime.} = [ + "Foo", + "Bar" +] + +var bar{.compileTime.} = { + 0: "Foo", + 1: "Bar" +}.toTable() + +macro fooM(): untyped = + for i, val in foo: + echo i, ": ", val + +macro barM(): untyped = + for i, val in bar: + echo i, ": ", val + +macro fooParam(x: static array[2, string]): untyped = + for i, val in x: + echo i, ": ", val + +macro barParam(x: static Table[int, string]): untyped = + for i, val in x: + echo i, ": ", val + +fooM() +barM() +fooParam(foo) +barParam(bar) + + +#----------------------------------------------------------------------------------------- +# issue #7546 +type + rangeB[N: static[int16]] = range[0'i16 .. N] + setB[N: static[int16]] = set[rangeB[N]] + +block: + var s : setB[14'i16] + + +#----------------------------------------------------------------------------------------- +# issue #9520 + +type + MyEnum = enum + Val1, Val2 + +proc myproc(a: static[MyEnum], b: int) = + if b < 0: + myproc(a, -b) + + echo $a + +myproc(Val1, -10) + + +#------------------------------------------------------------------------------------------ +# issue #6177 + +type + G[N,M:static[int], T] = object + o: T + +proc newG[N,M:static[int],T](x:var G[N,M,T], y:T) = + x.o = y+10*N+100*M + +proc newG[N,M:static[int],T](x:T):G[N,M,T] = result.newG(x) + +var x:G[2,3,int] +x.newG(4) +var y = newG[2,3,int](4) + |