Skip to content

Conversation

@CyrusNajmabadi
Copy link
Member

Fixes #75870

@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner November 13, 2024 01:27
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 13, 2024
{
public const string UnwrapArgument = nameof(UnwrapArgument);

private static readonly ImmutableDictionary<string, string?> s_unwrapArgumentProperties =
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to common location

var properties = unwrapArgument ? s_unwrapArgumentProperties : ImmutableDictionary<string, string?>.Empty;
if (changesSemantics)
properties = properties.Add(UseCollectionInitializerHelpers.ChangesSemanticsName, "");
var properties = GetDiagnosticProperties(unwrapArgument, useSpread, changesSemantics);
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to common location

nameof(ParallelEnumerable),
nameof(ParallelQuery),
// Special internal runtime interface that is optimized for fast path conversions of collections.
"IIListProvider"];
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to common location

Implements(type, compilation.IReadOnlyListOfTType());
}

bool IsIterable(ExpressionSyntax expression)
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to common location

internal sealed partial class CSharpUseCollectionExpressionForNewDiagnosticAnalyzer()
: AbstractCSharpUseCollectionExpressionDiagnosticAnalyzer(
IDEDiagnosticIds.UseCollectionExpressionForNewDiagnosticId,
EnforceOnBuildValues.UseCollectionExpressionForNew)
Copy link
Member Author

Choose a reason for hiding this comment

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

supports converting new List<...>(x) to [.. x]

arguments.Count == 1)
{
var argExpression = arguments[0].Expression;
if (argExpression
Copy link
Member Author

Choose a reason for hiding this comment

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

moved to helper.

@CyrusNajmabadi CyrusNajmabadi changed the title Add more cases supported by 'use collection expressoin' Add more cases supported by 'use collection expression' Nov 13, 2024
@CyrusNajmabadi
Copy link
Member Author

@akhera99 @dibarbet ptal.

{
void M()
{
const bool shouldParallelize = false;
Copy link
Member

Choose a reason for hiding this comment

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

is this necessary?

}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/71145")]
public async Task TestNotInParallelEnumerable2()
Copy link
Member

Choose a reason for hiding this comment

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

The "Not" in the name makes me think it should not convert to a collection expression

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct. We didn't update hte parallel one, only the non parallel one :)

@CyrusNajmabadi CyrusNajmabadi merged commit 747210f into dotnet:main Nov 14, 2024
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend the "Use collection expression" suggestion to scenarios requiring the spread operator

3 participants