17199, "mppf", "should 'new R(arg)' be able to run a 'proc init=' ?", "2021-02-19T18:30:03Z"
Today we have several data structures in the modules that implement both proc init(rhs: rhsType)
and proc init=(rhs: rhsType)
for a variety of rhsType
types. For example, there are these two functions implementing initialization of a list
from a range
:
It seems to be unfortunate that these initializers need to be repeated. So, this issue asks two questions:
- Should it be possible to implement one of these by calling the other? Does it work today to implement
init=
by callinginit
? Could we make it possible to implementinit
by callinginit=
? Note that even if simple cases work here,init
andinit=
have different strategies for instantiated or partially instantiated types (init
uses additional arguments whileinit=
usesthis.type
). Do we need some of the strategies from tertiary initializers to do this? (TODO tertiary initializers issue). - Should the compiler automatically enable code like
new list(myRange)
to runlist.init=(rhs: range)
if no suitablelist.init
is available? This question is related to the question of whether or not the compiler can use aninit=
with an appropriate different type RHS to implement a cast. (TODO cast issue).