Skip to content

Object variants can lead to crashes in debug mode or change type with release mode when kind is specified multiple times #106

@hourianto

Description

@hourianto

For example:

import jsony

type
  PayloadKind = enum
    kInt
    kFloat

  Payload = object
    case kind: PayloadKind
    of kInt:
      i: int64
    of kFloat:
      f: float64

const Input = """{"kind":"kFloat","f":3.14,"kind":"kInt"}"""

when defined(release):
  let parsed = Input.fromJson(Payload)
  doAssert parsed.kind == kInt
  doAssert parsed.i == 4614253070214989087'i64
  echo "release corruption reproduced: ", parsed.i
else:
  discard Input.fromJson(Payload)

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