E11061: call passes 2+ Boolean literals positionally - use named arguments for clarity

Category: E11xxx Code quality and IR analysis · Reported in phase: PRE_IR_CHECKS · Classification: BOOLEAN_ARGUMENTS_REQUIRE_NAMES · All error codes

What went wrong

A call passes 2 or more Boolean literal values (true/false) as positional arguments. Boolean literals carry zero semantic signal at a call site - "true, false" is completely opaque without checking the function signature.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 816 (Why does EK9 require named arguments for multiple Boolean...)

Rationale

A single Boolean literal is tolerable when context makes it obvious: setVisible(true), setReadOnly(false). But two or more Boolean literals in the same call are nearly always ambiguous.

Martin (Clean Code) recommends converting boolean parameters to separate functions. McConnell (Code Complete) recommends named constants for boolean arguments. EK9 takes a pragmatic middle ground: keep the parameters, but require naming at the call site when ambiguity arises.

How to fix it

Use named arguments on the entire call:

BAD:  createConnection("db", 5432, true, false)
GOOD: createConnection(host: "db", port: 5432, useSsl: true, autoReconnect: false)

EK9 requires all-or-nothing naming (E06240), so all arguments must be named when any are - this ensures complete self-documentation.

See also

  • E06240: either all parameters named or none
  • E06250: named parameters must match arguments
  • E11062: 4+ positional arguments require names

Examples

Every example is compiled by the EK9 compiler: the first fails exactly as captioned, the others fix it.

Fails with E11061: call passes 2+ Boolean literals positionally - use named arguments for clarity

#!ek9
defines module error.e11061.bad

  defines class

    Connection
      host as String: String()
      port as Integer: 0
      useSsl as Boolean: false
      autoReconnect as Boolean: false

      default private Connection()

      Connection()
        ->
          host as String
          port as Integer
          useSsl as Boolean
          autoReconnect as Boolean

        this.host: host
        this.port: port
        this.useSsl: useSsl
        this.autoReconnect: autoReconnect

      default operator ?
      default operator $

  defines function

    connect()
      <- rtn as String?
      connection <- Connection("db", 5432, true, false)
      rtn: $connection

Fixed: Name the arguments

#!ek9
defines module error.e11061.good

  defines class

    Connection
      host as String: String()
      port as Integer: 0
      useSsl as Boolean: false
      autoReconnect as Boolean: false

      default private Connection()

      Connection()
        ->
          host as String
          port as Integer
          useSsl as Boolean
          autoReconnect as Boolean

        this.host: host
        this.port: port
        this.useSsl: useSsl
        this.autoReconnect: autoReconnect

      default operator ?
      default operator $

  defines function

    connect()
      <- rtn as String?
      connection <- Connection(host: "db", port: 5432, useSsl: true, autoReconnect: false)
      rtn: $connection

Questions and answers

These Q&A entries show E11061 and its fix: