I tried to use [0] for a type name and it leads to crash
import typetraits, strutils
type
AbComponent* = object
template local*(expression: untyped): untyped {.dirty.} =
# this fails
# $(expression.type.name[0])
expression.type.name[0 .. 0]
var self = AbComponent()
echo local(2)
If you comment out, it crashes with
fatal.nim(39) sysFatal
Error: unhandled exception: index out of bounds, the container is empty [IndexError]
Running correctly and returning the first char
[0 .. 0] so this is a workaround$ nim -v
Nim Compiler Version 1.1.1 [Linux: amd64]
Compiled at 2019-12-02
Copyright (c) 2006-2019 by Andreas Rumpf
git hash: 2acf74d458accf65d969199a389c8dbc2eedab55
active boot switches: -d:release
Not related to templates afaict.
A bit more minimal example:
import typetraits
proc local(expression: int): char = expression.type.name[0]
echo local(1)
Not related to procs afaict.
A bit more minimal example:
import typetraits
echo int.name[0]
Most helpful comment
Not related to procs afaict.
A bit more minimal example: