E026: Auxiliary Constructor Needs Non-Implicit Parameter

This error is emitted when an auxiliary constructor (secondary constructor) only has implicit parameter lists without any non-implicit parameters.

Only the primary constructor is allowed to have an implicit-only parameter list. Auxiliary constructors must have at least one non-implicit parameter list. When a primary constructor has an implicit argslist, auxiliary constructors that call the primary constructor must specify the implicit value explicitly.


Example

class Example(implicit x: Int):
  def this(implicit x: String, y: Int) = this()(using y)

Error

-- [E026] Syntax Error: example.scala:2:39 -------------------------------------
2 |  def this(implicit x: String, y: Int) = this()(using y)
  |                                       ^
  |                   Auxiliary constructor needs non-implicit parameter list
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  | Only the primary constructor is allowed an implicit parameter list;
  | auxiliary constructors need non-implicit parameter lists. When a primary
  | constructor has an implicit argslist, auxiliary constructors that call the
  | primary constructor must specify the implicit value.
  |
  | To resolve this issue check for:
  |  - Forgotten parenthesis on this (def this() = { ... })
  |  - Auxiliary constructors specify the implicit value
   -----------------------------------------------------------------------------

Solution

// Add an empty non-implicit parameter list before the implicit one
class Example(implicit x: Int):
  def this()(implicit x: String, y: Int) = this()(using y)
// Alternative: use an explicit non-implicit parameter with a different type
class Example(implicit x: Int):
  def this(x: String, y: Int) = this()(using y)