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

C# 13: [TEST ONLY] Implicit index usage in initializers. #18562

Merged
merged 2 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static void Sink<T>(T t) { }

public static void SinkElem<T>(T[] ts) => Sink(ts[0]);

public static void SinkLastElem<T>(T[] ts) => Sink(ts[^1]);

public static void SinkListElem<T>(IList<T> list) => Sink(list[0]);

public static void SinkDictValue<T>(IDictionary<int, T> dict) => Sink(dict[0]);
Expand All @@ -21,6 +23,8 @@ public static void Sink<T>(T t) { }

public static T First<T>(T[] ts) => ts[0];

public static T Last<T>(T[] ts) => ts[^1];

public static T ListFirst<T>(IList<T> list) => list[0];

public static T DictIndexZero<T>(IDictionary<int, T> dict) => dict[0];
Expand Down Expand Up @@ -73,6 +77,15 @@ public void ArrayInitializerCSharp6NoFlow(A other)
Sink(First(c.As)); // no flow
}

public void ArrayInitializerImplicitIndexFlow()
{
var a = new A();
var c = new CollectionFlow() { As = { [^1] = a } };
Sink(c.As[^1]); // flow
SinkLastElem(c.As); // flow
Sink(Last(c.As)); // flow
}

public void ArrayAssignmentFlow()
{
var a = new A();
Expand All @@ -93,6 +106,16 @@ public void ArrayAssignmentNoFlow(A other)
Sink(First(@as)); // no flow
}

public void ArrayAssignmentImplicitIndexFlow()
{
var a = new A();
var @as = new A[1];
@as[^1] = a;
Sink(@as[^1]); // flow
SinkLastElem(@as); // flow
Sink(Last(@as)); // flow
}

public void ListAssignmentFlow()
{
var a = new A();
Expand Down
Loading