-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Open
Description
Steps to Reproduce:
Consider this code .NET lab:
class MyCollection<T> : IEnumerable<T>
{
private readonly List<T> _list;
IEnumerator<T> IEnumerable<T>.GetEnumerator() => _list.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => _list.GetEnumerator();
public MyCollection() { _list = new(); }
public MyCollection(params MyCollection<T> other) { _list = new(other); }
public void Add(T t) { _list.Add(t); }
}
class C
{
public void M()
{
MyCollection<int> c = [with(1)]; // Creation of params collection 'MyCollection<int>' results in an infinite chain of invocation of constructor 'MyCollection<T>.MyCollection()'.
}
}Diagnostic Id: CS9223
Expected Behavior:
No CS9223 is reported, because the call stack will be MyCollection(params MyCollection<T> other) --> MyCollection() --> .Add() and no infinite recursion is happened. This exact behavior is fixed under a test CollectionExpressionTests_WithElement_Extra.ParamsCycle_MultipleConstructors
Actual Behavior:
CS9223 is reported
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels