From 78b27ed7fa121d2cb032fa1b74ae434034bf8e23 Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 11 Mar 2013 08:42:35 +0100 Subject: bugfix: 'indexOf' for tuple fields works --- tests/run/tfieldindex.nim | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/run/tfieldindex.nim (limited to 'tests') 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") + -- cgit 1.4.1-2-gfad0