Looks like a bug to me, please report it on github. You can also add code
example below.
> in this small example i don't even use strings
Converters enable implicit conversion. And combined with templates (used in the
system library) it causes unexpected results:
template inspect(a: typed) =
if a is seq and a.len > 0:
if a[0] is byte:
echo "It is a sequence of bytes!"
elif a[0] is char:
echo "It is a sequence of chars!"
else:
echo "It is something else."
converter `toString`(a: seq[byte]): string = cast[ptr string](a.addr)[]
echo char is byte # false
inspect(@[byte 1, 2, 3]) # compiles and outputs: it is a sequence of chars!
Run
Consider using explicit conversion instead:
proc unsafeString(a: seq[byte]): string {.inline.} = cast[ptr
string](a.addr)[]
echo @[byte 1, 2, 3].unsafeString() # outputs: ^A^B^C
var query = @[byte 1,2,3]
query[0..1] = @[byte 8,8]
echo query # outputs: @[8, 8, 3]
Run