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
And it can be easily fixed:
proc `'flg`*(n: string): flg =
var number: uint
{.cast(raises: []).}:
discard parseUInt(n, number)
result = number.flg
But I have some questions:
If you add {.compileTime.} to the proc, the exception doesn't get tracked as it would be a compile error.
from std/parseutils import parseUInt
type flg = distinct uint8
proc `'flg`*(n: string): flg {.compileTime.} =
var number: uint
discard parseUInt(n, number)
result = number.flg
proc main {.raises: [].} =
let x = 0'flg # no error
IMO this is the best way to use this feature. The only reason string is used for these is to support huge numbers.