Hi, at the moment, initialization of user defined numeric literals raises
ValueError through the use of parseInt, parseUint, which makes their unusable
with the new effects system.
For example:
from std/parseutils import parseUInt
type flg = distinct uint8
proc `'flg`*(n: string): flg =
var number: uint
discard parseUInt(n, number)
result = number.flg
proc main {.raises: [].} =
let x = 0'flg # Error: `'flg`(r"0") can raise an unlisted exception:
ValueError
Run
And it can be easily fixed:
proc `'flg`*(n: string): flg =
var number: uint
{.cast(raises: []).}:
discard parseUInt(n, number)
result = number.flg
Run
But I have some questions:
1. Is this the intended behavior of the user defined numeric literals?
2. Is it correct to use {.cast(raises: []).} in this case?