> On Jun 1, 2023, at 10:59 AM, Brian Goetz <[email protected]> wrote: > > I think that there should be an explicit (and not synthetic) method_info for > the implicit constructor, with the obvious Code attribute (`defaultvalue` / > `areturn`.) > > My rationale is: "the declaration said there's a no-arg constructor, I should > be able to call it". And that intuition is entirely reasonable. Users > should be able to say `new Complex()` and get a default complex value. > (Maybe they can also say `Complex.default`; maybe we won't need that.) And > the same for reflection. > > Also, in case it is not obvious, the following class is illegal: > > value class X { > implicit X(); > X() { ... } > } > > because it is trying to declare the same constructor twice. An implicit > constructor is a constructor, just one for which the compiler can deduce > specific known semantics.
Agree with all of this. Some of these details were initially unclear a few weeks ago, but I think we've settled on a design in which the implicit constructor is a "real", invokable constructor, in addition to signaling some metadata about the class. > On 6/1/2023 10:47 AM, Dan Heidinga wrote: >> Alas representing implicit constructors with a `method_info` is not without >> costs: primarily specing how the method_info exists and explaining why it >> doesn't have a code attribute. There would be nothing special about the <vnew> method. It only exists as a code path for explicit constructor invocations. The "I have a default instance" metadata comes from ImplicitCreation. (Do we expect reflection to reconstruct ImplicitCreation+no-arg <vnew> --> 'Constructor.isImplicit' or 'ACC_IMPLICIT'? Maybe. Not entirely sure yet what the reflection surface will look like.)
