E07080: 'default' constructor with parameters is not supported

Category: E07xxx Full resolution · Reported in phase: SYMBOL_DEFINITION · Classification: INVALID_DEFAULT_CONSTRUCTOR · All error codes

What went wrong

You've used 'default' on a constructor that has PARAMETERS, but 'default' constructor specifically means zero-argument construction.

Worked examples

Compilable examples demonstrating this error and the correct fix:

  • ek9 -q 776 (Why can't a default constructor have parameters in EK9?)

Rationale

The 'default' keyword auto-generates sensible implementation for 0-arg constructor by initializing all fields to their default values.

How to fix it

  1. Remove parameters to use 'default'
  2. Or remove 'default' and provide manual implementation
  3. Can have both: default() AND parameterized constructors

Common causes

  • Misunderstanding 'default' keyword purpose
  • Trying to generate parameter-based constructor
  • Wanting auto-generation with parameters

See also

  • E07080: default constructor with params (this error)
  • E07090: default on regular method

Examples

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

Fails with E07080: 'default' constructor with parameters is not supported

#!ek9
defines module error.e07080.bad

  defines class

    Counter

      //A 'default' constructor is the generated no-argument one
      default Counter()
        -> start as Integer

Fixed: A default constructor takes no arguments: drop the parameter, or write the constructor out without default

#!ek9
defines module error.e07080.good.fix

  defines class

    Counter

      //A 'default' constructor is the generated no-argument one
      default Counter()

Fixed: Keep 'default' for the no-argument constructor, and write the one with parameters

#!ek9
defines module error.e07080.good

  defines class

    Counter
      count <- 0

      default Counter()

      Counter()
        -> start as Integer
        this.count: start

      default operator ?

Questions and answers

These Q&A entries show E07080 and its fix:

Found a problem?

If EK9 reported E07080 for a program you think is valid, or did not report it where it should have, use the compiler form with the smallest program that shows it. If this page is wrong or unclear, use the documentation form. Both are at github.com/ek9lang/ek9-issues.