How does EK9 validate argument counts when calling generic functions?
← Generics · Ref: Q656
EK9 validates that the number of arguments passed to a function or method matches the declared parameter count. Too many arguments raises E06280, too few raises E06290.
EXACT MATCH REQUIRED
A function declared with two parameters:
combine(a as String, b as String)
Must be called with exactly two arguments:
combine("hello", "world") // correct
TOO MANY (E06280)
Passing more arguments than declared:
combine("a", "b", "c") // ERROR: expects 2, got 3
TOO FEW (E06290)
Passing fewer arguments than declared:
combine("a") // ERROR: expects 2, got 1
GENERIC FUNCTION CALLS
Same validation applies to generic function calls:
transform(source as S) // needs exactly 1 argument transform(x, y) // ERROR: too many
NO OPTIONAL PARAMETERS
EK9 has no default parameter values (by design). Every declared parameter must receive an argument.
See Q597 for no default parameters design. See Q642 for constructor inference. See Q654 for type parameter count.
Example
defines module qa.genericsdeep.argumentcount defines function <?- Single parameter function. Requires exactly 1 argument. -?> square() as pure -> number as Integer <- rtn as Integer: number * number <?- Two parameter function. Requires exactly 2 arguments. -?> multiply() as pure -> factor1 as Integer factor2 as Integer <- rtn as Integer: factor1 * factor2 <?- Generic single parameter function. -?> echo() of type T as open -> item as T <- rtn as T: T(item) defines program ArgumentCountDemo() stdout <- Stdout() // === SINGLE ARG: exactly 1 === sq <- square(7) stdout.println(`Square of 7: ${sq}`) // === TWO ARGS: exactly 2 === product <- multiply(factor1: 6, factor2: 7) stdout.println(`Product: ${product}`) // === GENERIC SINGLE ARG === echoed <- echo(42) stdout.println(`Echoed: ${echoed}`) strEchoed <- echo("hello") stdout.println(`Str echoed: ${strEchoed}`)
Common mistakes
E06270 — square() declares exactly one parameter, so passing two arguments triggers E06270 (too many arguments). See ek9 -h E06270 for details.
Incorrect:
sq <- square(7, 3)
Correct:
sq <- square(7)
E06270 — multiply() declares two parameters (factor1 and factor2), so passing only one argument triggers E06270 (too few arguments). See ek9 -h E06270 for details.
Incorrect:
product <- multiply(factor1: 6)
Correct:
product <- multiply(factor1: 6, factor2: 7)
Other ways to ask this
- What are E06280 and E06290 too many or too few arguments?
- How does EK9 check function call argument counts?
- What happens if I pass wrong number of arguments to a generic function?
Coming from another language?
Java: exact argument count required (no defaults for methods). C++: default parameters allow fewer args. Rust: exact count required (no defaults). Go: exact count required (no defaults or varargs for regular funcs). Kotlin: default parameters allow fewer. Python: default params and *args. EK9: exact count always, no defaults by design (E06280/E06290).
Keywords: E06290, count, argument, validation, E06280, too many, type-parameter, function, too few, generic