Skip to content
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
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix analyzer [RCS1264](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1264) ([PR](https://github.com/dotnet/roslynator/pull/1666))
- Fix analyzer [RCS1229](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1229) ([PR](https://github.com/dotnet/roslynator/pull/1667))
- Fix analyzer [RCS1250](https://josefpihrt.github.io/docs/roslynator/analyzers/RCS1250) ([PR](https://github.com/dotnet/roslynator/pull/1652) by @aihnatiuk)

## [4.13.1] - 2025-02-23

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ protected override bool UseCollectionExpressionFromImplicit(ref SyntaxNodeAnalys
var implicitObjectCreation = (ImplicitObjectCreationExpressionSyntax)context.Node;

return implicitObjectCreation.ArgumentList?.Arguments.Any() != true
&& implicitObjectCreation.Initializer?.Expressions.Any(f => f.IsKind(SyntaxKind.SimpleAssignmentExpression)) != true
&& implicitObjectCreation.Initializer?.Expressions
.Any(f => f.IsKind(
SyntaxKind.SimpleAssignmentExpression,
SyntaxKind.ComplexElementInitializerExpression)) != true
&& UseCollectionExpression(ref context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1903,4 +1903,31 @@ void M2()
""", options: Options.AddConfigOption(ConfigOptionKeys.ObjectCreationTypeStyle, ConfigOptionValues.ObjectCreationTypeStyle_Implicit)
.AddConfigOption(ConfigOptionKeys.UseCollectionExpression, false));
}

[Fact, Trait(Traits.Analyzer, DiagnosticIdentifiers.UseImplicitOrExplicitObjectCreation)]
public async Task TestNoDiagnostic_ComplexElementInitializer()
{
await VerifyNoDiagnosticAsync("""
using System;
using System.Collections;
using System.Collections.Generic;
class C : IEnumerable<KeyValuePair<int, int>>
{
public IEnumerator<KeyValuePair<int, int>> GetEnumerator() => throw new System.NotImplementedException();

IEnumerator IEnumerable.GetEnumerator() => throw new System.NotImplementedException();

public void Add(int arg1, int arg2)
{
}

static C M()
{
C c = new() { { 1, 2 } };
return c;
}
}
""", options: Options.AddConfigOption(ConfigOptionKeys.ObjectCreationTypeStyle, ConfigOptionValues.ObjectCreationTypeStyle_Implicit)
.AddConfigOption(ConfigOptionKeys.UseCollectionExpression, true));
}
}
Loading