Skip to content

Commit dec1611

Browse files
authored
MA0075: Fix false-positive for array element reference operations (#601)
1 parent d09d775 commit dec1611

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/Meziantou.Analyzer/Internals/CultureSensitiveFormattingContext.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ public bool IsCultureSensitiveOperation(IOperation operation, CultureSensitiveOp
206206

207207
if (operation is IDefaultValueOperation defaultValue)
208208
return IsCultureSensitiveType(defaultValue.Type, format: null, instance: null, options);
209+
210+
if (operation is IArrayElementReferenceOperation arrayElementReference)
211+
return IsCultureSensitiveType(arrayElementReference.Type, format: null, instance: null, options);
209212

210213
// Unknown operation
211214
return true;

tests/Meziantou.Analyzer.Test/Rules/DoNotUseImplicitCultureSensitiveToStringAnalyzerTests.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ await CreateProjectBuilder()
125125
.ValidateAsync();
126126
}
127127

128+
[Fact]
129+
public async Task Concat_Char_String_NoDiagnostic()
130+
{
131+
var sourceCode = """
132+
class Test
133+
{
134+
void A(char[] c)
135+
{
136+
string str = "";
137+
str = c[0] + str;
138+
}
139+
}
140+
""";
141+
await CreateProjectBuilder()
142+
.WithSourceCode(sourceCode)
143+
.ValidateAsync();
144+
}
145+
128146
[Theory]
129147
[InlineData("abc[|{(sbyte)-1}|]")]
130148
[InlineData("abc[|{(short)-1}|]")]

0 commit comments

Comments
 (0)