gnolang/gno

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

MikaelVallenet opened this issue ยท 3 comments

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 ๐Ÿš€

thanks for tackling this!

moul commented

Go version: 1.17

is the project still working on this version?

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)