Skip to content

Encoding a struct with field which is a type definition implementing TextMarshaller ends with SIGSEGV #730

@nieomylnieja

Description

@nieomylnieja

Describe the bug

Encoding a struct with a field which is a type definition that implements TextMarshaller interface ends with a segmentation error.

To Reproduce

Playground link: https://go.dev/play/p/antYUlJajpY

package main

import (
	"os"

	"github.com/goccy/go-yaml"
)

type Foo struct {
	Bar Bar `json:"bar"`
}

type Bar string

func (x Bar) MarshalText() ([]byte, error) {
	return []byte(string(x)), nil
}

func main() {
	x := Foo{}
	enc := yaml.NewEncoder(os.Stdout)
	if err := enc.Encode(x); err != nil {
		panic(err)
	}
}

Expected behavior

No error occurs :)

Version Variables

  • Go version: 1.24.2
  • go-yaml's Version: v1.17.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions