Skip to content

TOML: using to_toml option may produce incorrect TOML #46454

@stephenll

Description

@stephenll

Here is is a simplified example to illustrate the issue I'm seeing with using the TOML writer with the to_toml option for writing a custom type. It seems that when using the to_toml option, TOML print doesn't print the correct TOML.

I expect the hello = "world" to not be combined with the [b] table.

I'm using Julia 1.8 on both a M1 Mac (arm64) and an Intel Mac.

Just looking to see if anyone else is seeing this and if my understanding is correct.

using TOML

struct Foo
    a::Int64
    b::Float64
end

struct Bar
    c::Float64
    d::String
end


f = Foo(2,9.9)
b = Bar(1.345, "hello")

dd = Dict("hello"=>"world", "f"=>f,  "b"=>b)

toDict(foo::Foo) = Dict("a"=>foo.a, "b"=>foo.b)
toDict(bar::Bar) = Dict("c"=>bar.c, "d"=>bar.d)

TOML.print(toDict,dd)

which results in the "hello" being added to the b table in the TOML.

[f]
b = 9.9
a = 2

[b]
c = 1.345
d = "hello"
hello = "world"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions