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

Struct embedding loses type information and causes failed parsing. #58

Closed
dhermes opened this issue Jul 25, 2021 · 4 comments
Closed

Struct embedding loses type information and causes failed parsing. #58

dhermes opened this issue Jul 25, 2021 · 4 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@dhermes
Copy link

dhermes commented Jul 25, 2021

package main

import (
	"fmt"

	"sigs.k8s.io/yaml"
)

type Outer struct {
	A string `json:"a" yaml:"a"`
	B string `json:"b" yaml:"b"`
}

type Inner struct {
	A string `json:"a" yaml:"a"`
}

type WithInline struct {
	Inner Inner  `json:",inline" yaml:",inline"`
	B     string `json:"b" yaml:"b"`
}

type WithEmbed struct {
	Inner `json:",inline" yaml:",inline"`
	B     string `json:"b" yaml:"b"`
}

func main() {
	o := Outer{}
	err := yaml.Unmarshal([]byte("a: 10\nb: 11\n"), &o)
	extra := ""
	if err != nil {
		extra = fmt.Sprintf(" [err=%v]", err)
	}
	fmt.Printf("o=%#v%s\n", o, extra)

	wi := WithInline{}
	err = yaml.Unmarshal([]byte("a: 10\nb: 11\n"), &wi)
	extra = ""
	if err != nil {
		extra = fmt.Sprintf(" [err=%v]", err)
	}
	fmt.Printf("wi=%#v%s\n", wi, extra)

	we := WithEmbed{}
	err = yaml.Unmarshal([]byte("a: 10\nb: 11\n"), &we)
	extra = ""
	if err != nil {
		extra = fmt.Sprintf(" [err=%v]", err)
	}
	fmt.Printf("we=%#v%s\n", we, extra)
}

yields

o=main.Outer{A:"10", B:"11"}
wi=main.WithInline{Inner:main.Inner{A:""}, B:"11"}
we=main.WithEmbed{Inner:main.Inner{A:""}, B:"11"} [err=error unmarshaling JSON: while decoding JSON: json: cannot unmarshal number into Go struct field WithEmbed.a of type string]
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Oct 23, 2021
inteon added a commit to amurant/yaml that referenced this issue Oct 29, 2021
Signed-off-by: Inteon <42113979+inteon@users.noreply.github.com>
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Nov 22, 2021
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

@k8s-ci-robot
Copy link

@k8s-triage-robot: Closing this issue.

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue or PR with /reopen
  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants