Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOML Integer cannot be unmarshalled as a float32 #571

Closed
jkongie opened this issue Jul 21, 2021 · 2 comments
Closed

TOML Integer cannot be unmarshalled as a float32 #571

jkongie opened this issue Jul 21, 2021 · 2 comments
Labels
bug Issues describing a bug in go-toml. v2 Issues impacting the v2 major version.
Milestone

Comments

@jkongie
Copy link

jkongie commented Jul 21, 2021

Describe the bug
Marshalling a struct with a Float value as an integer returns output which when Unmarshalled back into the struct, returns an error toml: cannot store TOML integer into a Go float32.

To Reproduce

package main
import (
	"fmt"
	"github.com/pelletier/go-toml/v2"
)
type Foo struct {
	Float float32
}
func main() {
	foo := Foo{
		Float: 1,
	}
	b, err := toml.Marshal(foo)
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(string(b))
	// Output: Float = 1
	foo2 := Foo{}
	err = toml.Unmarshal(b, &foo2)
	if err != nil {
		fmt.Println(err)
		// Output: toml: cannot store TOML integer into a Go float32
	}
	fmt.Println(foo2)
}

Output

Float = 1

toml: cannot store TOML integer into a Go float32
{0}

ExpectedOutput

Float = 1.0

{1}

Expected behavior

It should be able to marshal an struct with a integer as a float, and unmarshal it back into the struct.

Versions

  • go-toml: v2.0.0-beta.3
  • go: version 1.16
  • operating system: macOS

Additional context
Add any other context about the problem here that you think may help to diagnose.

@pelletier pelletier added the bug Issues describing a bug in go-toml. label Jul 27, 2021
@pelletier
Copy link
Owner

Thanks for the report! I wonder if some other conversions are missing.

@pelletier pelletier added this to the v2.0.0-beta.5 milestone Jul 29, 2021
@pelletier pelletier added the v2 Issues impacting the v2 major version. label Oct 3, 2021
pelletier pushed a commit that referenced this issue Oct 14, 2021
Fixes #571

Co-authored-by: Sterling Hanenkamp <sterling@ziprecruiter.com>
@pelletier
Copy link
Owner

This should be fixed in 4984dcb. Feel free to re-open if not!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issues describing a bug in go-toml. v2 Issues impacting the v2 major version.
Projects
None yet
Development

No branches or pull requests

2 participants