Skip to content

Commit 391f64f

Browse files
authored
Fix OverloadFinder (#795)
1 parent 8b18a59 commit 391f64f

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Meziantou.Analyzer/Internals/OverloadFinder.cs

+11-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public static bool HasSimilarParameters(IMethodSymbol method, IMethodSymbol othe
151151
break;
152152
}
153153

154-
if (i == method.Parameters.Length && j == otherMethod.Parameters.Length)
154+
if (i == method.Parameters.Length && j == otherMethod.Parameters.Length && additionalParameterIndex == additionalParameterTypes.Length)
155155
return true;
156156
}
157157

@@ -162,26 +162,36 @@ public static bool HasSimilarParameters(IMethodSymbol method, IMethodSymbol othe
162162

163163
foreach (var param in method.Parameters)
164164
{
165+
var found = false;
165166
for (var i = 0; i < otherMethodParameters.Length; i++)
166167
{
167168
if (otherMethodParameters[i].Type.IsEqualTo(param.Type))
168169
{
169170
otherMethodParameters = otherMethodParameters.RemoveAt(i);
171+
found = true;
170172
break;
171173
}
172174
}
175+
176+
if (!found)
177+
return false;
173178
}
174179

175180
foreach (var paramType in additionalParameterTypes)
176181
{
182+
var found = false;
177183
for (var i = 0; i < otherMethodParameters.Length; i++)
178184
{
179185
if (otherMethodParameters[i].Type.IsEqualTo(paramType))
180186
{
181187
otherMethodParameters = otherMethodParameters.RemoveAt(i);
188+
found = true;
182189
break;
183190
}
184191
}
192+
193+
if (!found)
194+
return false;
185195
}
186196

187197
if (otherMethodParameters.Length == 0)

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

+11
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,17 @@ await CreateProjectBuilder()
2929
.ValidateAsync();
3030
}
3131

32+
[Fact]
33+
public async Task NoReport_TimeSpanFromSeconds()
34+
{
35+
const string SourceCode = """
36+
_ = System.TimeSpan.FromSeconds(1);
37+
""";
38+
await CreateProjectBuilder()
39+
.WithOutputKind(OutputKind.ConsoleApplication)
40+
.WithSourceCode(SourceCode)
41+
.ValidateAsync();
42+
}
3243

3344
[Fact]
3445
public async Task NotAvailable()

0 commit comments

Comments
 (0)