flyx / NimYAML

YAML implementation for Nim
https://nimyaml.org
Other
186 stars 36 forks source link

Strange compiler error, representChild(value[], ts, c) can raise #99

Closed StefanSalewski closed 3 years ago

StefanSalewski commented 3 years ago

As I had some trouble with Nim JSON and tuples, I tried again your YAML.

With recent Nim compiler and @#head version of your YAML:

I just noted that JSON works with array instead of tuple, but your Yaml gives even with array that strange compiler error:

#import json, marshal
import yaml/serialization, streams
type
  #V2 = tuple[x, y: float]
  V2 = array[2, float]

type
  Element = ref object of RootRef
    # style: Styles
    p: seq[V2]
    at: seq[Text] # attached text
    hover: bool
    selected: bool
    gx, gy: int # text grab
    isNew: bool

# type
  Text = ref object of Element
    text: string
    parent: Element # new, for easy reattaching, and maybe a graphical parent indication (arrow)
    detached: bool # maybe with new parent field this boolean is redundant. 
    sizeInPixel: bool

type
  Line = ref object of Element

type
  Trace = ref object of Element

type
  Rect = ref object of Element

type
  Circ = ref object of Element

type
  Pad = ref object of Element
    cornerRadius: float

type
  Path = ref object of Element

type
  Pin = ref object of Element

type
  Group = ref object of Element
    lines: seq[Line]
    circs: seq[Circ]
    texts: seq[Text]
    rects: seq[Rect]
    pads: seq[Pad]
    paths: seq[Path]
    pins: seq[Pin]
    traces: seq[Trace]

proc main =
  discard
  var g = Group()
  var l = Line()
  l.p.add([1.0,2.0])

  #echo marshal.`$$`(g)
  #echo ""
  #echo json.pretty(json.`%*`(g))
  var s = newFileStream("out.yaml", fmWrite)
  dump(g, s)
  s.close()

main()
$ nim c jmom.nim 
Hint: used config file '/home/salewski/Nim/config/nim.cfg' [Conf]
Hint: used config file '/home/salewski/Nim/config/config.nims' [Conf]
.................................................................................................
/home/salewski/SDTold/jmom.nim(67, 7) template/generic instantiation of `dump` from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(1417, 25) template/generic instantiation of `represent` from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(1394, 17) template/generic instantiation of `representChild` from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(1308, 20) template/generic instantiation of `representObject` from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(981, 21) template/generic instantiation of `genRepresentObject` from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(970, 25) template/generic instantiation of `representChild` from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(1248, 18) template/generic instantiation of `representObject` from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(440, 19) template/generic instantiation of `representChild` from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(1308, 20) template/generic instantiation of `representObject` from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(981, 21) template/generic instantiation of `genRepresentObject` from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(970, 25) template/generic instantiation of `representChild` from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(75, 15) template/generic instantiation from here
/home/salewski/.nimble/pkgs/yaml-#head/yaml/serialization.nim(1252, 41) Error: representChild(value[], ts, c) can raise an unlisted exception: YamlStreamError
flyx commented 3 years ago

The raise annotations are still somewhat quirky as they predate Nim's Errors/Defects distinction, but your problem should be fixed now.