Skip to content

Commit c7103d6

Browse files
mchernyavskyyopox
authored andcommitted
INSP: Fix default parameters handling in Wrong number of type arguments inspection
1 parent b4cbf53 commit c7103d6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/kotlin/org/rust/ide/inspections/RsWrongGenericArgumentsNumberInspection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private fun checkFunctionCall(actualArgs: Int, expectedRequiredParams: Int, expe
9090
return when {
9191
actualArgs > expectedTotalParams ->
9292
if (expectedRequiredParams != expectedTotalParams) "at most $expectedTotalParams" else "$expectedTotalParams"
93-
actualArgs in 1 until expectedTotalParams ->
93+
actualArgs in 1 until expectedRequiredParams ->
9494
if (expectedRequiredParams != expectedTotalParams) "at least $expectedRequiredParams" else "$expectedTotalParams"
9595
else -> null
9696
}

src/test/kotlin/org/rust/ide/inspections/RsWrongGenericArgumentsNumberInspectionTest.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,29 @@ class RsWrongGenericArgumentsNumberInspectionTest : RsInspectionsTestBase(RsWron
327327
}
328328
""")
329329

330+
fun `test call expr with default type argument`() = checkByText("""
331+
struct S<A, B = i32>(A, B);
332+
fn main() {
333+
S(1, 2);
334+
S::<>(1, 2);
335+
S::<i32>(1, 2);
336+
S::<i32, i32>(1, 2);
337+
<error descr="Wrong number of type arguments: expected at most 2, found 3 [E0107]">S::<i32, i32, i32>(1, 2)</error>;
338+
}
339+
""")
340+
341+
fun `test method call with default type argument`() = checkByText("""
342+
struct S;
343+
impl S { fn foo<A, B = i32>(&self, a: A, b: B) {} }
344+
fn main() {
345+
S.foo(1, 2);
346+
S.foo::<>(1, 2);
347+
S.foo::<i32>(1, 2);
348+
S.foo::<i32, i32>(1, 2);
349+
S.<error descr="Wrong number of type arguments: expected at most 2, found 3 [E0107]">foo::<i32, i32, i32>(1, 2)</error>;
350+
}
351+
""")
352+
330353
fun `test dyn trait`() = checkByText("""
331354
trait Trait<A> {}
332355
fn foo() {

0 commit comments

Comments
 (0)