Consider this code:
var a = @[1, 2, 3]
echo a[a.len]
Of course we will get an IndexError: "index out of bounds". However, this code will pass.
var s = "123"
echo s[s.len]
We even can modify the last null char. Is this a bug or a default behavior? Anyway, I think it's not safe.
this has been fixed in devel some time ago
nim --version Nim Compiler Version 0.18.1 [MacOSX: amd64] Compiled at 2018-07-24 Copyright (c) 2006-2018 by Andreas Rumpf
git hash: d5c9255cab9c111f8fa930e4cd42d6671877bd9d active boot switches: -d:release
inim INim 0.3.0 Nim Compiler Version 0.18.1 [MacOSX: amd64] at /Users/timothee/.nimble/bin/nim >>> var s = "123" >>> echo s[s.len] inim_1532494547
Error: unhandled exception: index out of bounds [IndexError] Error: execution of an external program failed: '/private/tmp/inim_1532494547 ' >>> echo s[s.len-1] 3