Skip to content

Commit

Permalink
Merge pull request #18562 from michaelnebel/csharp/implicitindex
Browse files Browse the repository at this point in the history
C# 13: [TEST ONLY] Implicit index usage in initializers.
  • Loading branch information
michaelnebel authored Jan 23, 2025
2 parents 9286596 + c38ad4a commit dcdc12f
Show file tree
Hide file tree
Showing 5 changed files with 850 additions and 731 deletions.
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

0 comments on commit dcdc12f

Please sign in to comment.