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

Collection literals: address comments #68793

Merged
merged 7 commits into from
Jun 29, 2023

Conversation

cston
Copy link
Member

@cston cston commented Jun 27, 2023

Address PROTOTYPE comments.

@cston cston requested review from a team as code owners June 27, 2023 00:21
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 27, 2023
@cston cston changed the base branch from main to features/CollectionLiterals June 27, 2023 00:22
@cston cston removed request for a team June 27, 2023 00:22
@@ -548,18 +548,13 @@ BoundExpression convertArrayElement(BoundExpression element, TypeSymbol elementT
}

var implicitReceiver = new BoundObjectOrCollectionValuePlaceholder(syntax, isNewInstance: true, targetType) { WasCompilerGenerated = true };
// PROTOTYPE: When generating a List<T>, should we use the well-known
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROTOTYPE

Added open issue to test plan #66418.

var collectionInitializerAddMethodBinder = this.WithAdditionalFlags(BinderFlags.CollectionInitializerAddMethod);
var builder = ArrayBuilder<BoundExpression>.GetInstance(node.Elements.Length);
foreach (var element in node.Elements)
{
var result = element switch
{
BoundBadExpression => element,
// PROTOTYPE: Should spread elements support target type?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROTOTYPE

Added open issue to test plan #66418.

@@ -1173,7 +1173,6 @@ static void Main()
}
}
""";
// PROTOTYPE: Should compile and run successfully: expectedOutput: "[1, 2, 3], "
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROTOTYPE

Natural type for collection literals is not supported, so [x] and [y] are target-typed only.

@@ -1325,7 +1324,6 @@ static void Main()
CompileAndVerify(new[] { source, s_collectionExtensions }, expectedOutput: "(System.Int32[]) [1, 2, 3], ");
}

// PROTOTYPE: Test other variance cases.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROTOTYPE

See TypeInference_38, _39.

@@ -2087,10 +2207,6 @@ static void Main()
}
}
""";
// PROTOTYPE: Confirm we should generate ListBase<int> instances for both x and y.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROTOTYPE

Natural type is not supported.

@@ -4156,7 +4272,7 @@ static void Main()
[ConditionalTheory(typeof(CoreClrOnly))]
[CombinatorialData]
public void SpreadElement_01(
[CombinatorialValues("IEnumerable", "IEnumerable<int>", "int[]", "List<int>", "Span<int>", "ReadOnlySpan<int>")] string spreadType,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IEnumerable

Tested separate in SpreadElement_11.

@@ -4584,7 +4697,6 @@ static void Main()
}
""";
var comp = CreateCompilation(source);
// PROTOTYPE: Should spread elements support target type? (Should we infer IEnumerable<int>?)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROTOTYPE

Added open issue to test plan #66418.

@@ -4606,7 +4718,6 @@ static string[] Append(string a, string b, bool c)
}
}
""";
// PROTOTYPE: Should spread elements support target type? (Should we infer IEnumerable<string>?)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PROTOTYPE

Added open issue to test plan #66418.

@@ -6303,33 +6441,5 @@ static async Task<T> F<T>(T t)
""";
CompileAndVerify(new[] { source, s_collectionExtensions }, expectedOutput: "[3, 1, 2, 4], ");
}

[ConditionalFact(typeof(CoreClrOnly), AlwaysSkip = "PROTOTYPE: 'IAsyncEnumerable<int>' does not contain a definition for 'GetAwaiter'")]
public void Async_03()
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Async_03

Added open issue to test plan #66418: support IAsyncEnumerable<T> for spread element?

@cston
Copy link
Member Author

cston commented Jun 27, 2023

    // PROTOTYPE: Should this compile successfully?

Added open issue to test plan [#66418](#66418).


Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/CollectionLiteralTests.cs:2036 in a207dec. [](commit_id = a207dec, deletion_comment = True)

@@ -5365,8 +5364,8 @@ public void CastVersusIndexAmbiguity24_B()
[Fact]
public void CastVersusIndexAmbiguity24_C()
{
// PROTOTYPE: This is not a great diagnostic. Users could easily run into this and be confused. Can we do
// better. For example:
// This is not a great diagnostic. Users could easily run into this and be confused. Can we do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracking issue?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This particular case involves a dictionary element which is not currently supported. I've logged an issue to improve the diagnostic for the previous example (A)[1]: #68862.

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment, otherwise LGTM

@@ -3836,7 +3836,6 @@ internal uint GetValEscape(BoundExpression expr, uint scopeOfTheContainingExpres
return GetValEscape(switchExpr.SwitchArms.SelectAsArray(a => a.Value), scopeOfTheContainingExpression);

case BoundKind.CollectionLiteralExpression:
// PROTOTYPE: Revisit if spans may be optimized to avoid heap allocation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a test plan #66418 item tracking this now.

@cston cston merged commit 77d3192 into dotnet:features/CollectionLiterals Jun 29, 2023
@cston cston deleted the collections-comments branch June 29, 2023 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants