-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
kind:bugA bug in the code. Does not apply to documentation, specs, etc.A bug in the code. Does not apply to documentation, specs, etc.topic:stdlib:serialization
Description
YAML::ParseContext#record_anchor, which is used by the various from_yaml methods and YAML::Serializable, does nothing to an object unless it has a reference type. That means an alias will fail to resolve if its target has a value type, even though YAML.parse will succeed:
require "yaml"
record Foo, x : Int32, y : Int32 do
include YAML::Serializable
end
yaml = <<-YAML
x: &anchor 123
y: *anchor
YAML
YAML.parse(yaml) # => {"x" => 123, "y" => 123}
Foo.from_yaml(yaml) # Unhandled exception: Error deserializing alias (Exception)
Hash(String, Int32).from_yaml(yaml) # Unhandled exception: Error deserializing alias (Exception)The exception type is not even YAML::ParseException, just Exception.
Reference type anchors are okay:
record Bar, x : String, y : String do
include YAML::Serializable
end
yaml = <<-YAML
x: &anchor "abc"
y: *anchor
YAML
bar = Bar.from_yaml(yaml) # => Bar(@x="abc", @y="abc")
bar.x.same?(bar.y) # => true
h = Hash(String, String).from_yaml(yaml) # => {"x" => "abc", "y" => "abc"}
h["x"].same?(h["y"]) # => trueMetadata
Metadata
Assignees
Labels
kind:bugA bug in the code. Does not apply to documentation, specs, etc.A bug in the code. Does not apply to documentation, specs, etc.topic:stdlib:serialization