Why does passing the wrong type to a function cause E06270 in EK9?

← Generics · Ref: Q840

EK9 does NOT auto-convert between incompatible types. Passing an Integer where a String is expected triggers E06270 PARAMETER_MISMATCH.

NO IMPLICIT CONVERSION

Unlike Java (which auto-boxes and calls toString()), EK9 requires explicit type conversion:

  acceptsString(123)     // ERROR E06270 — Integer is not String
  acceptsString($123)    // CORRECT — $ converts Integer to String

THE $ OPERATOR

The $ operator converts any type to its String representation:

  age <- 25
  label <- $age           // "25" as String

INSIDE BACKTICK STRINGS

Use ${expression} for interpolation:

  greeting <- `Age is ${age}`

FUNCTION PARAMETERS MUST MATCH

  showName(name as String) — expects String
  showName("Steve")       — correct
  showName(42)            — ERROR E06270
  showName($42)           — correct (converts to "42")

See Q194 for generic type basics. See Q238 for operator overview.

Example

defines module qa.genericsdeep.parameter.type.mismatch

  defines function

    acceptsString() as pure
      -> phrase as String
      <- rtn as String: phrase

    acceptsInteger() as pure
      -> amount as Integer
      <- rtn as Integer: amount

  defines program

    ParameterTypeDemo()
      stdout <- Stdout()

      // === CORRECT: matching types ===
      greeting <- acceptsString("Hello EK9")
      stdout.println(greeting)

      score <- acceptsInteger(42)
      stdout.println($score)

      // === CORRECT: explicit $ conversion ===
      converted <- acceptsString($score)
      stdout.println(converted)

      // === CORRECT: interpolation inside backticks ===
      message <- `Score is ${score}`
      stdout.println(message)

Common mistakes

E06270 — Integer cannot be implicitly converted to String. Use the $ operator to explicitly convert: $123 produces the String "123". See ek9 -h E06270 for details.

Incorrect:

      converted <- acceptsString(score)

Correct:

      converted <- acceptsString($score)
Other ways to ask this
  • What triggers E06270 PARAMETER_MISMATCH?
  • Why can't I pass Integer where String is expected in EK9?
  • How do I convert types explicitly in EK9?

Coming from another language?

Java: Auto-boxes primitives and calls toString() implicitly in string concatenation. Integer passed to String parameter causes compile error but string concat works. Python: Dynamically typed, type mismatches caught only at runtime. Rust: No implicit conversions, requires .to_string() or Into trait. Kotlin: Requires explicit .toString(), similar to EK9. EK9: No implicit conversions, uses $ operator for string conversion.

Keywords: conversion, explicit, string, E06270, mismatch, dollar, type, parameter