diff options
-rw-r--r-- | lib/pure/typetraits.nim | 15 | ||||
-rw-r--r-- | tests/run/ttypetraits.nim | 24 |
2 files changed, 39 insertions, 0 deletions
diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim new file mode 100644 index 000000000..45b79dcb6 --- /dev/null +++ b/lib/pure/typetraits.nim @@ -0,0 +1,15 @@ +# +# +# Nimrod's Runtime Library +# (c) Copyright 2012 Nimrod Contributors +# +# See the file "copying.txt", included in this +# distribution, for details about the copyright. +# + +## This module defines compile-time reflection procs for +## working with types + +proc name*(t: typedesc): string {.magic: "TypeTrait".} + ## Returns the name of the given type + diff --git a/tests/run/ttypetraits.nim b/tests/run/ttypetraits.nim new file mode 100644 index 000000000..5b683bef0 --- /dev/null +++ b/tests/run/ttypetraits.nim @@ -0,0 +1,24 @@ +discard """ + msg: "int\nstring\nTBar[int]" + output: "int\nstring\nTBar[int]" +""" + +import typetraits + +proc foo(x) = + static: + var t = type(x) + echo t.name + + echo x.type.name + +type + TBar[U] = object + x: U + +var bar: TBar[int] + +foo 10 +foo "test" +foo bar + |