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

Polyglot Notebook: Stack overflow when creating instance of class with recursive IEnumerable #3625

Open
2 tasks
duyang76 opened this issue Aug 5, 2024 · 2 comments

Comments

@duyang76
Copy link

duyang76 commented Aug 5, 2024

I can replicate this issue with a bare minimum example: a class implementing IEnumerable of itself with an empty child list.

Version: 1.0.522904

  • OS
    • Windows 10
  • Frontend
    • Visual Studio Code

I cannot post from my company's internal network, so I'm typing from my phone and taking a screenshot below. But it is pretty obvious.

IMG20240805111604

@duyang76
Copy link
Author

duyang76 commented Aug 29, 2024

Can someone take a look or provide some insight?

The class definition is below. It runs fine. But if I create an instance in polyglot notebook, the kernel crashes due to stack overflow. There is no infinite-loop in the code, just recursive call on the child nodes (which is empty). It seems that the .net interactive or polyglot causes infinite-loop somewhere.

public class TestIEnumerator : IEnumerable<TestIEnumerator>
{
	private List<TestIEnumerator> children;	
	public List<TestIEnumerator> Children
	{
		get
		{
			if (children==null) children = new List<TestIEnumerator>();
			return children;
		}
	}
	
	public IEnumerator<TestIEnumerator> GetEnumerator()
	{
		List<TestIEnumerator> childList = new List<TestIEnumerator>();
		recurseChildren(this, ref childList, 0);
		return childList.GetEnumerator();
	}
	
	private void recurseChildren(TestIEnumerator f, ref List<TestIEnumerator>coll, int lvl)
	{
		coll.Add(f);
		Console.WriteLine("RecurseChildren level: " + lvl);
		foreach(TestIEnumerator tmp in f.Children)
		{
			RecurseChildren(tmp, ref coll, lvl+1);
		}
	}
	
	System.Collection.IEnumerator System.Collection.IEnumerable.GetEnumerator()
	{
		return this.GetEnumerator();
	}
}

@duyang76 duyang76 changed the title Stack overflow when creating instance of class with recursive IEnumerable Polyglot Notebook: Stack overflow when creating instance of class with recursive IEnumerable Sep 11, 2024
@duyang76
Copy link
Author

Can someone provide some thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant