I created a type in a unittest and wanted to create a converter and got a compile error that converters are only allowed at the top level. Below is a simple example, what makes converters so special that they can only be defined at the top level? This is 0.10.3 as of today.
$ nim -v ; cat -n x.nim ; nim c --hints:off x.nim
Nim Compiler Version 0.10.3 (2015-04-14) [Linux: amd64]
Copyright (c) 2006-2015 by Andreas Rumpf
git hash: e281d4137025c5ed310c388b05be90578a5c2ff9
active boot switches: -d:release
1 proc x() =
2 type
3 MyType = object
4 id: int
5
6 converter toInt(mt: MyType): int =
7 result = cast[int](mt.id)
8
9 var
10 mt: MyType
11 i: int
12
13 mt.id = 3
14 i = mt.toInt()
15 echo "mt=", mt, " i=", i
x.nim(6, 2) Error: 'converter' is only allowed at top level
It seems odd we can add local types, procs, templates... but not converters.
Is this a limitation of the compiler implementation and could be addressed with effort or actually limitation of the language definition in some way?