diff options
author | Araq <rumpf_a@web.de> | 2013-03-11 08:42:35 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-03-11 08:42:35 +0100 |
commit | 78b27ed7fa121d2cb032fa1b74ae434034bf8e23 (patch) | |
tree | 365c6446a5ab04fa7711368b5079c4d8a3204c1f /tests | |
parent | 5ac5bedc66c94a781c4a23fa6d0407c012276aa7 (diff) | |
download | Nim-78b27ed7fa121d2cb032fa1b74ae434034bf8e23.tar.gz |
bugfix: 'indexOf' for tuple fields works
Diffstat (limited to 'tests')
-rw-r--r-- | tests/run/tfieldindex.nim | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/run/tfieldindex.nim b/tests/run/tfieldindex.nim new file mode 100644 index 000000000..3ffa65e58 --- /dev/null +++ b/tests/run/tfieldindex.nim @@ -0,0 +1,21 @@ +discard """ + output: "1" +""" + +type + TMyTuple = tuple[a, b: int] + +proc indexOf*(t: typedesc, name: string): int {.compiletime.} = + ## takes a tuple and looks for the field by name. + ## returs index of that field. + var + d: t + i = 0 + for n, x in fieldPairs(d): + if n == name: return i + i.inc + raise newException(EInvalidValue, "No field " & name & " in type " & + astToStr(t)) + +echo TMyTuple.indexOf("b") + |