diff options
Diffstat (limited to 'tests/template')
27 files changed, 460 insertions, 435 deletions
diff --git a/tests/template/t2416.nim b/tests/template/t2416.nim deleted file mode 100644 index f73880718..000000000 --- a/tests/template/t2416.nim +++ /dev/null @@ -1,2 +0,0 @@ -import i2416 -i2416() diff --git a/tests/template/t2do.nim b/tests/template/t2do.nim deleted file mode 100644 index f5f6393dc..000000000 --- a/tests/template/t2do.nim +++ /dev/null @@ -1,23 +0,0 @@ -discard """ - output: "8.0" -""" - -# bug #2057 - -proc mpf_get_d(x: int): float = float(x) -proc mpf_cmp_d(a: int; b: float): int = 0 - -template toFloatHelper(result, tooSmall, tooLarge: untyped) = - result = mpf_get_d(a) - if result == 0.0 and mpf_cmp_d(a,0.0) != 0: - tooSmall - if result == Inf: - tooLarge - -proc toFloat*(a: int): float = - toFloatHelper(result) do: - raise newException(ValueError, "number too small") - do: - raise newException(ValueError, "number too large") - -echo toFloat(8) diff --git a/tests/template/tcan_access_hidden_field.nim b/tests/template/tcan_access_hidden_field.nim deleted file mode 100644 index a6f6490cc..000000000 --- a/tests/template/tcan_access_hidden_field.nim +++ /dev/null @@ -1,9 +0,0 @@ -discard """ - output: 33 -""" - -import mcan_access_hidden_field - -var myfoo = createFoo(33, 44) - -echo myfoo.geta diff --git a/tests/template/tdefault_nil.nim b/tests/template/tdefault_nil.nim deleted file mode 100644 index 783f77388..000000000 --- a/tests/template/tdefault_nil.nim +++ /dev/null @@ -1,14 +0,0 @@ - -# bug #2629 -import sequtils, os - -template glob_rst(basedir: string = ""): untyped = - if baseDir.len == 0: - to_seq(walk_files("*.rst")) - else: - to_seq(walk_files(basedir/"*.rst")) - -let - rst_files = concat(glob_rst(), glob_rst("docs")) - -when isMainModule: echo rst_files diff --git a/tests/template/template_issues.nim b/tests/template/template_issues.nim new file mode 100644 index 000000000..8599b161a --- /dev/null +++ b/tests/template/template_issues.nim @@ -0,0 +1,209 @@ +discard """ +output: ''' +@[] +5 +0 +a +hi +''' +""" + + +import macros, json + + +block t2057: + proc mpf_get_d(x: int): float = float(x) + proc mpf_cmp_d(a: int; b: float): int = 0 + + template toFloatHelper(result, tooSmall, tooLarge: untyped) = + result = mpf_get_d(a) + if result == 0.0 and mpf_cmp_d(a,0.0) != 0: + tooSmall + if result == Inf: + tooLarge + + proc toFloat(a: int): float = + toFloatHelper(result) do: + raise newException(ValueError, "number too small") + do: + raise newException(ValueError, "number too large") + + doAssert toFloat(8) == 8.0 + + + +import sequtils, os +block t2629: + template glob_rst(basedir: string = ""): untyped = + if baseDir.len == 0: + to_seq(walk_files("*.rst")) + else: + to_seq(walk_files(basedir/"*.rst")) + + let rst_files = concat(glob_rst(), glob_rst("docs")) + + when isMainModule: echo rst_files + + +block t5417: + macro genBody: untyped = + let sbx = genSym(nskLabel, "test") + when true: + result = quote do: + block `sbx`: + break `sbx` + else: + template foo(s1, s2) = + block s1: + break s2 + result = getAst foo(sbx, sbx) + + proc test() = + genBody() + + + +block t909: + template baz() = + proc bar() = + var x = 5 + iterator foo(): int {.closure.} = + echo x + var y = foo + discard y() + + macro test(): untyped = + result = getAst(baz()) + + test() + bar() + + + +block t993: + type PNode = ref object of RootObj + + template litNode(name, ty) = + type name = ref object of PNode + val: ty + litNode PIntNode, int + + template withKey(j: JsonNode; key: string; varname, + body: untyped): typed = + if j.hasKey(key): + let varname{.inject.}= j[key] + block: + body + + var j = parsejson("{\"zzz\":1}") + withkey(j, "foo", x): + echo(x) + + + + +block t1337: + template someIt(a, pred): untyped = + var it {.inject.} = 0 + pred + + proc aProc(n: auto) = + n.someIt(echo(it)) + + aProc(89) + + + +import mlt +block t4564: + type Bar = ref object of RootObj + proc foo(a: Bar): int = 0 + var a: Bar + let b = a.foo() > 0 + + + +block t8052: + type + UintImpl[N: static[int], T: SomeUnsignedInt] = object + raw_data: array[N, T] + + template genLoHi(TypeImpl: untyped): untyped = + template loImpl[N: static[int], T: SomeUnsignedInt](dst: TypeImpl[N div 2, T], src: TypeImpl[N, T]) = + let halfSize = N div 2 + for i in 0 ..< halfSize: + dst.raw_data[i] = src.raw_data[i] + + proc lo[N: static[int], T: SomeUnsignedInt](x: TypeImpl[N,T]): TypeImpl[N div 2, T] {.inline.}= + loImpl(result, x) + + genLoHi(UintImpl) + + var a: UintImpl[4, uint32] + + a.raw_data = [1'u32, 2'u32, 3'u32, 4'u32] + doAssert a.lo.raw_data.len == 2 + doAssert a.lo.raw_data[0] == 1 + doAssert a.lo.raw_data[1] == 2 + + + +block t2585: + type + RenderPass = object + state: ref int + RenderData = object + fb: int + walls: seq[RenderPass] + Mat2 = int + Vector2[T] = T + Pixels=int + + template use(fb: int, st: untyped): untyped = + echo "a ", $fb + st + echo "a ", $fb + + proc render(rdat: var RenderData; passes: var openarray[RenderPass]; proj: Mat2; + indexType = 1) = + for i in 0 ..< len(passes): + echo "blah ", repr(passes[i]) + + proc render2(rdat: var RenderData; screenSz: Vector2[Pixels]; proj: Mat2) = + use rdat.fb: + render(rdat, rdat.walls, proj, 1) + + + +block t4292: + template foo(s: string): string = s + proc variadicProc(v: varargs[string, foo]) = echo v[0] + variadicProc("a") + + + +block t2670: + template testTemplate(b: bool): typed = + when b: + var a = "hi" + else: + var a = 5 + echo a + testTemplate(true) + + + +block t4097: + var i {.compileTime.} = 2 + + template defineId(t: typedesc) = + const id {.genSym.} = i + static: inc(i) + proc idFor(T: typedesc[t]): int {.inline, raises: [].} = id + + defineId(int8) + defineId(int16) + + doAssert idFor(int8) == 2 + doAssert idFor(int16) == 3 \ No newline at end of file diff --git a/tests/template/template_various.nim b/tests/template/template_various.nim new file mode 100644 index 000000000..f1135d5bb --- /dev/null +++ b/tests/template/template_various.nim @@ -0,0 +1,251 @@ +discard """ +output: ''' +i2416 +33 +foo55 +foo8.0 +fooaha +bar7 +immediate +10 +4true +132 +''' +""" + +import macros + + + + +import i2416 +i2416() + + +import mcan_access_hidden_field +var myfoo = createFoo(33, 44) +echo myfoo.geta + + +import mgensym_generic_cross_module +foo(55) +foo 8.0 +foo "aha" +bar 7 + + + +block generic_templates: + type + SomeObj = object of RootObj + Foo[T, U] = object + x: T + y: U + + template someTemplate[T](): tuple[id: int32, obj: T] = + var result: tuple[id: int32, obj: T] = (0'i32, T()) + result + + let ret = someTemplate[SomeObj]() + + # https://github.com/nim-lang/Nim/issues/7829 + proc inner[T](): int = + discard + + template outer[A](): untyped = + inner[A]() + + template outer[B](x: int): untyped = + inner[B]() + + var i1 = outer[int]() + var i2 = outer[int](i1) + + # https://github.com/nim-lang/Nim/issues/7883 + template t1[T: int|int64](s: string): T = + var t: T + t + + template t1[T: int|int64](x: int, s: string): T = + var t: T + t + + var i3: int = t1[int]("xx") + + + +block tgetast_typeliar: + proc error(s: string) = quit s + + macro assertOrReturn(condition: bool; message: string): typed = + var line = condition.lineInfo() + result = quote do: + block: + if not likely(`condition`): + error("Assertion failed: " & $(`message`) & "\n" & `line`) + return + + macro assertOrReturn(condition: bool): typed = + var message = condition.toStrLit() + result = getAst assertOrReturn(condition, message) + + proc point(size: int16): tuple[x, y: int16] = + # returns random point in square area with given `size` + assertOrReturn size > 0 + + + +type + MyFloat = object + val: float +converter to_myfloat(x: float): MyFloat {.inline.} = + MyFloat(val: x) + +block pattern_with_converter: + proc `+`(x1, x2: MyFloat): MyFloat = + MyFloat(val: x1.val + x2.val) + + proc `*`(x1, x2: MyFloat): MyFloat = + MyFloat(val: x1.val * x2.val) + + template optMul{`*`(a, 2.0)}(a: MyFloat): MyFloat = + a + a + + func floatMyFloat(x: MyFloat): MyFloat = + result = x * 2.0 + + func floatDouble(x: float): float = + result = x * 2.0 + + doAssert floatDouble(5) == 10.0 + + + +block prefer_immediate: + # Test that immediate templates are preferred over non-immediate templates + + 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: untyped) {.immediate.} = echo "immediate" + template foo(a, b: bool) = echo "foo bool" + template foo(a, b: char) = echo "foo char" + + foo(undeclaredIdentifier, undeclaredIdentifier2) + + + + +block procparshadow: + template something(name: untyped) = + proc name(x: int) = + var x = x # this one should not be rejected by the compiler (#5225) + echo x + + something(what) + what(10) + + # bug #4750 + type + O = object + i: int + OP = ptr O + + template alf(p: pointer): untyped = + cast[OP](p) + + proc t1(al: pointer) = + var o = alf(al) + + proc t2(alf: pointer) = + var x = alf + var o = alf(x) + + + +block symchoicefield: + type Foo = object + len: int + + var f = Foo(len: 40) + + template getLen(f: Foo): int = f.len + + doAssert f.getLen == 40 + # This fails, because `len` gets the nkOpenSymChoice + # treatment inside the template early pass and then + # it can't be recognized as a field anymore + + + +import os, times +include "sunset.tmpl" +block ttempl: + const + tabs = [["home", "index"], + ["news", "news"], + ["documentation", "documentation"], + ["download", "download"], + ["FAQ", "question"], + ["links", "links"]] + + + var i = 0 + for item in items(tabs): + var content = $i + var file: File + if open(file, changeFileExt(item[1], "html"), fmWrite): + write(file, sunsetTemplate(current=item[1], ticker="", content=content, + tabs=tabs)) + close(file) + else: + write(stdout, "cannot open file for writing") + inc(i) + + + +block ttempl4: + template `:=`(name, val: untyped): typed = + var name = val + + ha := 1 * 4 + hu := "ta-da" == "ta-da" + echo ha, hu + + + + +import mtempl5 +block ttempl5: + echo templ() + + #bug #892 + proc parse_to_close(value: string, index: int, open='(', close=')'): int = + discard + + # Call parse_to_close + template get_next_ident: typed = + discard "{something}".parse_to_close(0, open = '{', close = '}') + + get_next_ident() + + #identifier expected, but found '(open|open|open)' + #bug #880 (also example in the manual!) + template typedef(name: untyped, typ: typedesc) = + type + `T name` {.inject.} = typ + `P name` {.inject.} = ref `T name` + + typedef(myint, int) + var x: PMyInt + + + +block templreturntype: + template `=~` (a: int, b: int): bool = false + var foo = 2 =~ 3 + + + + diff --git a/tests/template/tgenerictemplates.nim b/tests/template/tgenerictemplates.nim deleted file mode 100644 index 142505b1a..000000000 --- a/tests/template/tgenerictemplates.nim +++ /dev/null @@ -1,37 +0,0 @@ -type - SomeObj = object of RootObj - - Foo[T, U] = object - x: T - y: U - -template someTemplate[T](): tuple[id: int32, obj: T] = - var result: tuple[id: int32, obj: T] = (0'i32, T()) - result - -let ret = someTemplate[SomeObj]() - -# https://github.com/nim-lang/Nim/issues/7829 -proc inner*[T](): int = - discard - -template outer*[A](): untyped = - inner[A]() - -template outer*[B](x: int): untyped = - inner[B]() - -var i1 = outer[int]() -var i2 = outer[int](i1) - -# https://github.com/nim-lang/Nim/issues/7883 -template t1[T: int|int64](s: string): T = - var t: T - t - -template t1[T: int|int64](x: int, s: string): T = - var t: T - t - -var i3: int = t1[int]("xx") - diff --git a/tests/template/tgensym_generic_cross_module.nim b/tests/template/tgensym_generic_cross_module.nim deleted file mode 100644 index 856ab676d..000000000 --- a/tests/template/tgensym_generic_cross_module.nim +++ /dev/null @@ -1,14 +0,0 @@ -discard """ - output: '''foo55 -foo8.0 -fooaha -bar7''' -""" -# bug #5419 -import mgensym_generic_cross_module - -foo(55) -foo 8.0 -foo "aha" -bar 7 - diff --git a/tests/template/tgensym_label.nim b/tests/template/tgensym_label.nim deleted file mode 100644 index fd3b0a1ee..000000000 --- a/tests/template/tgensym_label.nim +++ /dev/null @@ -1,18 +0,0 @@ - -# bug #5417 -import macros - -macro genBody: untyped = - let sbx = genSym(nskLabel, "test") - when true: - result = quote do: - block `sbx`: - break `sbx` - else: - template foo(s1, s2) = - block s1: - break s2 - result = getAst foo(sbx, sbx) - -proc test() = - genBody() diff --git a/tests/template/tgetast_typeliar.nim b/tests/template/tgetast_typeliar.nim deleted file mode 100644 index c9a612582..000000000 --- a/tests/template/tgetast_typeliar.nim +++ /dev/null @@ -1,23 +0,0 @@ - -# just ensure this keeps compiling: - -import macros - -proc error(s: string) = quit s - -macro assertOrReturn*(condition: bool; message: string): typed = - var line = condition.lineInfo() - result = quote do: - block: - if not likely(`condition`): - error("Assertion failed: " & $(`message`) & "\n" & `line`) - return - -macro assertOrReturn*(condition: bool): typed = - var message = condition.toStrLit() - result = getAst assertOrReturn(condition, message) - -proc point*(size: int16): tuple[x, y: int16] = - # returns random point in square area with given `size` - - assertOrReturn size > 0 diff --git a/tests/template/tissue909.nim b/tests/template/tissue909.nim deleted file mode 100644 index 6786ff48c..000000000 --- a/tests/template/tissue909.nim +++ /dev/null @@ -1,16 +0,0 @@ -import macros - -template baz() = - proc bar() = - var x = 5 - iterator foo(): int {.closure.} = - echo x - var y = foo - discard y() - -macro test(): untyped = - result = getAst(baz()) - echo(treeRepr(result)) - -test() -bar() diff --git a/tests/template/tissue993.nim b/tests/template/tissue993.nim deleted file mode 100644 index 552890bb4..000000000 --- a/tests/template/tissue993.nim +++ /dev/null @@ -1,20 +0,0 @@ - -type PNode* = ref object of RootObj - -template litNode(name, ty) = - type name* = ref object of PNode - val*: ty -litNode PIntNode, int - -import json - -template withKey*(j: JsonNode; key: string; varname, - body: untyped): typed = - if j.hasKey(key): - let varname{.inject.}= j[key] - block: - body - -var j = parsejson("{\"zzz\":1}") -withkey(j, "foo", x): - echo(x) diff --git a/tests/template/tit.nim b/tests/template/tit.nim deleted file mode 100644 index 76b1d151b..000000000 --- a/tests/template/tit.nim +++ /dev/null @@ -1,11 +0,0 @@ - -# bug #1337 - -template someIt(a, pred): untyped = - var it {.inject.} = 0 - pred - -proc aProc(n: auto) = - n.someIt(echo(it)) - -aProc(89) diff --git a/tests/template/tlt.nim b/tests/template/tlt.nim deleted file mode 100644 index 75c7dd991..000000000 --- a/tests/template/tlt.nim +++ /dev/null @@ -1,7 +0,0 @@ - -import mlt -# bug #4564 -type Bar* = ref object of RootObj -proc foo(a: Bar): int = 0 -var a: Bar -let b = a.foo() > 0 diff --git a/tests/template/tnested_template.nim b/tests/template/tnested_template.nim deleted file mode 100644 index 37166009d..000000000 --- a/tests/template/tnested_template.nim +++ /dev/null @@ -1,23 +0,0 @@ -# bug #8052 - -type - UintImpl*[N: static[int], T: SomeUnsignedInt] = object - raw_data*: array[N, T] - -template genLoHi(TypeImpl: untyped): untyped = - template loImpl[N: static[int], T: SomeUnsignedInt](dst: TypeImpl[N div 2, T], src: TypeImpl[N, T]) = - let halfSize = N div 2 - for i in 0 ..< halfSize: - dst.raw_data[i] = src.raw_data[i] - - proc lo*[N: static[int], T: SomeUnsignedInt](x: TypeImpl[N,T]): TypeImpl[N div 2, T] {.inline.}= - loImpl(result, x) - -genLoHi(UintImpl) - -var a: UintImpl[4, uint32] - -a.raw_data = [1'u32, 2'u32, 3'u32, 4'u32] -assert a.lo.raw_data.len == 2 -assert a.lo.raw_data[0] == 1 -assert a.lo.raw_data[1] == 2 diff --git a/tests/template/tpattern_with_converter.nim b/tests/template/tpattern_with_converter.nim deleted file mode 100644 index e0632552b..000000000 --- a/tests/template/tpattern_with_converter.nim +++ /dev/null @@ -1,27 +0,0 @@ -discard """ - output: 10.0 -""" - -type - MyFloat = object - val: float - -converter to_myfloat*(x: float): MyFloat {.inline.} = - MyFloat(val: x) - -proc `+`(x1, x2: MyFloat): MyFloat = - MyFloat(val: x1.val + x2.val) - -proc `*`(x1, x2: MyFloat): MyFloat = - MyFloat(val: x1.val * x2.val) - -template optMul{`*`(a, 2.0)}(a: MyFloat): MyFloat = - a + a - -func floatMyFloat(x: MyFloat): MyFloat = - result = x * 2.0 - -func floatDouble(x: float): float = - result = x * 2.0 - -echo floatDouble(5) \ No newline at end of file diff --git a/tests/template/tprefer_immediate.nim b/tests/template/tprefer_immediate.nim deleted file mode 100644 index 3a4cfc07b..000000000 --- a/tests/template/tprefer_immediate.nim +++ /dev/null @@ -1,15 +0,0 @@ -discard """ - output: '''immediate''' -""" - -# Test that immediate templates are preferred over non-immediate templates - -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: 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/tprocparshadow.nim b/tests/template/tprocparshadow.nim deleted file mode 100644 index de1c2d941..000000000 --- a/tests/template/tprocparshadow.nim +++ /dev/null @@ -1,30 +0,0 @@ -discard """ - output: "10" -""" - -template something(name: untyped) = - proc name(x: int) = - var x = x # this one should not be rejected by the compiler (#5225) - echo x - -something(what) -what(10) - -# bug #4750 - -type - O = object - i: int - - OP = ptr O - -template alf(p: pointer): untyped = - cast[OP](p) - - -proc t1(al: pointer) = - var o = alf(al) - -proc t2(alf: pointer) = - var x = alf - var o = alf(x) diff --git a/tests/template/tstmt_semchecked_twice.nim b/tests/template/tstmt_semchecked_twice.nim deleted file mode 100644 index c6463ae06..000000000 --- a/tests/template/tstmt_semchecked_twice.nim +++ /dev/null @@ -1,30 +0,0 @@ - -# bug #2585 - -type - RenderPass = object - state: ref int - - RenderData* = object - fb: int - walls: seq[RenderPass] - - Mat2 = int - Vector2[T] = T - Pixels=int - -template use*(fb: int, st: untyped): untyped = - echo "a ", $fb - st - echo "a ", $fb - -proc render(rdat: var RenderData; passes: var openarray[RenderPass]; proj: Mat2; - indexType = 1) = - for i in 0 .. <len(passes): - echo "blah ", repr(passes[i]) - - - -proc render2*(rdat: var RenderData; screenSz: Vector2[Pixels]; proj: Mat2) = - use rdat.fb: - render(rdat, rdat.walls, proj, 1) diff --git a/tests/template/tsymchoicefield.nim b/tests/template/tsymchoicefield.nim deleted file mode 100644 index 4483c2aa2..000000000 --- a/tests/template/tsymchoicefield.nim +++ /dev/null @@ -1,11 +0,0 @@ -type Foo = object - len: int - -var f = Foo(len: 40) - -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/ttemp_in_varargs.nim b/tests/template/ttemp_in_varargs.nim deleted file mode 100644 index be78e6ef2..000000000 --- a/tests/template/ttemp_in_varargs.nim +++ /dev/null @@ -1,9 +0,0 @@ -discard """ - output: '''a''' -""" - -# bug #4292 - -template foo(s: string): string = s -proc variadicProc*(v: varargs[string, foo]) = echo v[0] -variadicProc("a") diff --git a/tests/template/ttempl.nim b/tests/template/ttempl.nim deleted file mode 100644 index c022201f2..000000000 --- a/tests/template/ttempl.nim +++ /dev/null @@ -1,27 +0,0 @@ -# Test the new template file mechanism - -import - os, times - -include "sunset.tmpl" - -const - tabs = [["home", "index"], - ["news", "news"], - ["documentation", "documentation"], - ["download", "download"], - ["FAQ", "question"], - ["links", "links"]] - - -var i = 0 -for item in items(tabs): - var content = $i - var file: File - if open(file, changeFileExt(item[1], "html"), fmWrite): - write(file, sunsetTemplate(current=item[1], ticker="", content=content, - tabs=tabs)) - close(file) - else: - write(stdout, "cannot open file for writing") - inc(i) diff --git a/tests/template/ttempl4.nim b/tests/template/ttempl4.nim deleted file mode 100644 index d1d26385f..000000000 --- a/tests/template/ttempl4.nim +++ /dev/null @@ -1,7 +0,0 @@ - -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 deleted file mode 100644 index fd3ea0cad..000000000 --- a/tests/template/ttempl5.nim +++ /dev/null @@ -1,28 +0,0 @@ - -import mtempl5 - -echo templ() - -#bug #892 - -proc parse_to_close(value: string, index: int, open='(', close=')'): int = - discard - -# Call parse_to_close -template get_next_ident: typed = - discard "{something}".parse_to_close(0, open = '{', close = '}') - -get_next_ident() - - -#identifier expected, but found '(open|open|open)' - -#bug #880 (also example in the manual!) - -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/ttemplreturntype.nim b/tests/template/ttemplreturntype.nim deleted file mode 100644 index 642fa1b72..000000000 --- a/tests/template/ttemplreturntype.nim +++ /dev/null @@ -1,4 +0,0 @@ - -template `=~` (a: int, b: int): bool = false -var foo = 2 =~ 3 - diff --git a/tests/template/twhen_gensym.nim b/tests/template/twhen_gensym.nim deleted file mode 100644 index f1a8d0eb7..000000000 --- a/tests/template/twhen_gensym.nim +++ /dev/null @@ -1,13 +0,0 @@ -discard """ - output: "hi" -""" - -# bug #2670 -template testTemplate(b: bool): typed = - when b: - var a = "hi" - else: - var a = 5 - echo a - -testTemplate(true) diff --git a/tests/template/typedescids.nim b/tests/template/typedescids.nim deleted file mode 100644 index 1df2f69fb..000000000 --- a/tests/template/typedescids.nim +++ /dev/null @@ -1,17 +0,0 @@ -discard """ - output: '''2 3''' -""" - -# bug #4097 - -var i {.compileTime.} = 2 - -template defineId*(t: typedesc) = - const id {.genSym.} = i - static: inc(i) - proc idFor*(T: typedesc[t]): int {.inline, raises: [].} = id - -defineId(int8) -defineId(int16) - -echo idFor(int8), " ", idFor(int16) |