Skip to content

Cannot use default parameters on init method #844

@supercooldave

Description

@supercooldave

Using default parameters on the init method results in compilation errors. For example,

local class A
  -- does not compile
  def init(i : int = 0) : unit
    println(i)
  end
  
  -- compiles and works
  def other(i : int = 0) : unit
    println(i)
  end
end

results in error:

"Init.enc" (line 3, column 3)
Constructor method 'init' can only be called during object creation
In expression: 
  this.init(0)
In expression: 
  return(this.init(0))
In method '_init1' of type 'unit'
In class 'A'

This is undoubtedly due to the way methods using default parameters are compiled, which is incompatible with the restrictions on init.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions