@@ -9,12 +9,15 @@ import {RecursiveVisitor} from "@server/visitor/visitor"
99import {
1010 Enum ,
1111 FunctionBase ,
12+ Parameter ,
1213 Struct ,
1314 TypeAlias ,
1415 TypeParameter ,
1516} from "@server/languages/tolk/psi/Decls"
1617import { CallLike , NamedNode } from "@server/languages/tolk/psi/TolkNode"
1718import { Reference } from "@server/languages/tolk/psi/Reference"
19+ import { NeverTy , TypeParameterTy , VoidTy } from "@server/languages/tolk/types/ty"
20+ import { typeOf } from "@server/languages/tolk/type-inference"
1821
1922import { Inspection , InspectionIds } from "./Inspection"
2023
@@ -49,10 +52,11 @@ export class CallArgumentsCountMismatchInspection implements Inspection {
4952 const deltaSelf = this . isInstanceMethodCall ( call ) ? 1 : 0
5053 const args = call . arguments ( )
5154 const argsCount = args . length + deltaSelf
52- const maxParams = called . parameters ( ) . length
55+ const parameters = called . parameters ( )
56+ const maxParams = parameters . length
5357
5458 let minParams = maxParams
55- while ( minParams > 0 && called . parameters ( ) [ minParams - 1 ] . defaultValue ( ) !== null ) {
59+ while ( minParams > 0 && this . canBeOmitted ( parameters [ minParams - 1 ] ) ) {
5660 minParams --
5761 }
5862
@@ -106,4 +110,20 @@ export class CallArgumentsCountMismatchInspection implements Inspection {
106110 // instance method call like foo.bar()
107111 return true
108112 }
113+
114+ private canBeOmitted ( parameter : Parameter ) : boolean {
115+ if ( parameter . defaultValue ( ) !== null ) {
116+ return true
117+ }
118+
119+ const type = typeOf ( parameter . node , parameter . file ) ?. baseType ( )
120+ if (
121+ type instanceof TypeParameterTy &&
122+ ( type . defaultType instanceof NeverTy || type . defaultType instanceof VoidTy )
123+ ) {
124+ return true
125+ }
126+
127+ return type instanceof NeverTy || type instanceof VoidTy
128+ }
109129}
0 commit comments