How does EK9 validate function and method parameters?

← Code Quality · Ref: Q745

EK9 validates function and method parameters comprehensively at compile time.

NAMED PARAMETERS MUST MATCH (E06250)

When using named parameters in a call, the names must match the parameter names in the function definition. Misspelled or incorrect parameter names are rejected.

FUNCTION PARAMETER MISMATCH (E06270)

Argument types must match parameter types. EK9 has no implicit type conversions. Passing an Integer where a String is expected is a compile-time error. Use explicit conversion operators like $ for string conversion.

REQUIRE NO ARGUMENTS (E06310)

Stream call and async operators require zero-argument supplier functions. Piping a function that takes parameters into a call operator is rejected.

INVALID NUMBER OF PARAMETERS (E06320)

Dispatcher overloads must have matching parameter counts. All handler methods must accept the same number of parameters as the dispatcher entry point.

See Q694 for named arguments patterns. See Q596 for function parameters.

Example

defines module qa.codequality.parametervalidation

  defines function

    greet() as pure
      -> name as String
      <- rtn as String: `Hello, ${name}`

    createUser() as pure
      ->
        name as String
        age as Integer
      <- rtn as String: `${name} (age ${age})`

    doubleIt() as pure
      -> number as Integer
      <- rtn as Integer: number * 2

  defines program

    ParameterValidationDemo()
      stdout <- Stdout()

      //Correct parameter types
      stdout.println(greet("Alice"))
      stdout.println(createUser("Bob", 25))
      stdout.println(`Doubled: ${doubleIt(21)}`)

      //Correct: explicit conversion with $
      count <- 42
      stdout.println(greet($count))

Common mistakes

E06270 — Function 'greet' expects a String but received an Integer. EK9 has no implicit type conversion. Use the $ operator to convert to String explicitly. See ek9 -h E06270 for details.

Incorrect:

greet(count)

Correct:

greet($count)

E50060 — String has no toUpperCase() method. Use upperCase() instead. See ek9 -h E50060 for details.

Incorrect:

stdout.println(greet("Alice").toUpperCase())

Correct:

stdout.println(greet("Alice"))

E50060 — String has no toString() method. createUser() already returns a String. See ek9 -h E50060 for details.

Incorrect:

stdout.println(createUser("Bob", 25).toString())

Correct:

stdout.println(createUser("Bob", 25))

E50060 — Integer has no toString() method. Use string interpolation or the $ operator. See ek9 -h E50060 for details.

Incorrect:

stdout.println(doubleIt(21).toString())

Correct:

stdout.println(`Doubled: ${doubleIt(21)}`)
Other ways to ask this
  • What is E06250 named parameters must match in EK9?
  • What is E06270 function parameter mismatch in EK9?
  • What is E06310 require no arguments in EK9?

Coming from another language?

Java: implicit widening conversions allowed. Python: duck typing, no compile-time checks. Rust: no implicit conversions, explicit Into/From traits. Go: no implicit conversions. Kotlin: limited implicit conversions. EK9: zero implicit conversions, all parameter types checked at compile time.

Keywords: E06250, E06310, argument, named, E06270, mismatch, validation, type, parameter, quality, conversion, E06320