Skip to content

Invalid numeric enum ordinals become invalid enum states in release #107

Description

@hourianto

Numeric enum parsing uses v = T(parseInt(strV)). In debug this can abort with RangeDefect. In release it becomes unchecked and constructs enum values outside the declared ordinal range.

Verified PoC, run with and without -d:danger:

import jsony

type Color = enum
  cRed
  cBlue

when defined(release):
  let two = "2".fromJson(Color)
  let large = "999".fromJson(Color)
  doAssert ord(two) == 2
  doAssert ord(large) > ord(high(Color))
  echo "release invalid enum ordinals reproduced: ", ord(two), " / ", ord(large)
else:
  discard "2".fromJson(Color)

Found by GPT 5.4.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions