Skip to content

YAML round-trip loses literal data: string "null" becomes '', float/long literals serialize to {} and deserialize to null #83

Closed

Description

@matt-edmondson

What's wrong

YamlSerializer (Coder/Serialization/YamlSerializer.cs) loses literal values in two ways.

  1. String literals that look like YAML scalars. SerializeLiteralExpression (~line 842) stores the raw literal.Value and lets the YAML emitter decide whether to quote it. Literal.Text("null") is written as value: null, unquoted, and deserializes as a string literal with value ''. The same risk applies to ~ and to other strings the emitter doesn't quote but the reader interprets as a non-string scalar.
  2. Float and long literals. The serializer's switch (~lines 165-176) only handles LiteralExpression<string|int|bool|double>. Literal.SingleValue(1.5f) and Literal.BigNumberValue(5000000000L) are public helpers (Coder/Ast/LiteralExpression.cs ~100-107), but they serialize as literal<Single>: {} and literal<Int64>: {}. The value is dropped silently, and Deserialize returns null for the node. Every language generator also throws NotSupportedException for these two types, because TryGenerateCommonNode doesn't know about them either.

Repro (executed in a probe test)

var s = new YamlSerializer();
var back = s.Deserialize(s.Serialize(Literal.Text("null")));        // value '' — expected "null"
var f = s.Deserialize(s.Serialize(Literal.SingleValue(1.5f)));       // null — expected literal 1.5f
var l = s.Deserialize(s.Serialize(Literal.BigNumberValue(5000000000L))); // null

Why it matters

YAML is the persistence format for ASTs and graphs. Saving and reloading a document silently changes a string constant or deletes a numeric literal, and nothing reports an error.

Suggested fix / acceptance criteria

  • Always emit string literal values as quoted scalars, or at least quote any value that YAML would parse as null, bool or number.
  • Either support float/long literals end-to-end (serializer, deserializer, TryGenerateCommonNode), or remove the SingleValue/BigNumberValue helpers so they can't be constructed.
  • Add round-trip tests for Text("null"), Text("true"), Text("123"), Text("~"), and for float and long literals if they are kept.

Activity

  1. added
    bug
    on Sep 26, 2026
  2. matt-edmondson commented on Sep 26, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

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

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions