flyx / NimYAML

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

Can not dump floats #141

Closed NickatelbNornkirn closed 7 months ago

NickatelbNornkirn commented 7 months ago

Errors are raised whenever I try to dump an object with one or more floats. Here is a minimal example:

type Foo = object
  a: float

Dumper().dump(Foo(a: 255), stream)

This raises the following errors:

[...]/src/my_file.nim(63, 11) template/generic instantiation of `dump` from here
[...]/yaml/dumping.nim(128, 25) template/generic instantiation of `represent` from here
here
[...]/yaml/native.nim(1795, 10) template/generic instantiation of `representChild` from here
here
[...]/yaml/native.nim(1758, 8) template/generic instantiation of `representObject` from here
here
[...]/yaml/native.nim(1344, 21) template/generic instantiation of `genRepresentObject` from here
here
[...]/yaml/native.nim(1322, 24) template/generic instantiation of `:tmp` from here
here
[...]/yaml/native.nim(1316, 14) template/generic instantiation of `representChild` from here
here
[...]/yaml/native.nim(1758, 8) template/generic instantiation of `representObject` from here
here
[...]/yaml/native.nim(454, 30) Error: type mismatch
Expression: scalarEvent(".inf", tag, scalarStyleFor(ctx, T))
  [1] ".inf": string
  [2] tag: Tag
  [3] scalarStyleFor(ctx, T): ScalarStyle

Expected one of (first mismatch at [position]):
[2] proc scalarEvent(content: string; props: Properties; style: ScalarStyle = ssAny;
                 startPos: Mark = Mark(); endPos: Mark = Mark()): Event
[3] proc scalarEvent(content: string = ""; tag: Tag = yTagQuestionMark;
                 anchor: Anchor = yAnchorNone; style: ScalarStyle = ssAny;
                 startPos: Mark = Mark(); endPos: Mark = Mark()): Event

nimble.nim(229)          buildFromDir

This does not happen if a change the type of Foo.a to something else (e.g. int or string).

flyx commented 7 months ago

Regression introduced in 2.0.0. Shows that the tests are lacking.

Fixed it, new version 2.1.1 is out containing the fix. Can't have stuff this basic not working, can we?