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

bug: crash stack overflow / size exceeded when printing value of self referencing structure #2850

Closed
MikaelVallenet opened this issue Sep 26, 2024 · 3 comments

Comments

@MikaelVallenet
Copy link
Contributor

MikaelVallenet commented Sep 26, 2024

crash stack overflow when printing value of self referencing struct

Description

When a structure refers to itself (e.g. linked list, tree ...etc), printing its value with %v flag causes the VM to crash.
In go this program displays &{user [] [] <nil> <nil>} and run with no problem.

Related: #1315

program:

package main

import "fmt"

type Role struct {
	Name        string
	Permissions []string
	Users       []string
	Next        *Role
	Prev        *Role
}

func main() {
	userRole := &Role{
		Name:        "user",
		Permissions: []string{},
		Users:       []string{},
		Next:        nil,
		Prev:        nil,
	}

	fmt.Printf("%v", userRole)
}

Your environment

  • Go version: 1.17
  • OS and CPU architecture: linux/amd64

Expected behaviour

print &{user [] [] <nil> <nil>}

Actual behaviour

crash w/ stack overflow

Proposed solution

I think it could come from infinite recursive on self referencing struct, i would like to assign myself to the issue and work on a fix in the next days 🚀

@thehowl
Copy link
Member

thehowl commented Sep 26, 2024

thanks for tackling this!

@moul
Copy link
Member

moul commented Sep 27, 2024

Go version: 1.17

is the project still working on this version?

@thehowl
Copy link
Member

thehowl commented Oct 2, 2024

Thanks for the issue; I'll close this as a won't fix as a real solution for printing these structures in gonative would require named type support in reflect.

#2851 (comment)

@thehowl thehowl closed this as not planned Won't fix, can't repro, duplicate, stale Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
3 participants