scala / scala-dev

Scala 2 team issues. Not for user-facing bugs or directly actionable user-facing improvements. For build/test/infra and for longer-term planning and idea tracking. Our bug tracker is at https://github.com/scala/bug/issues
Apache License 2.0
130 stars 15 forks source link

trait constructor woes #191

Open retronym opened 8 years ago

retronym commented 8 years ago

Scala omits the trait constructor if the template body has only only abstract defs.

This leads to two binary fragilities:

If a trait that was previously a pure interface is recompiled and becomes a regular trait with a constructor, previously compiled subclasses will fail to call the constructor.

Conversely, if a previously regular trait becomes pure, previously compiled subclasses will incur a linkage error calling the now-absent constructor:

https://gist.github.com/af3037454509de9412fc8e1d5d38d43c

The absense/presence of this constructor is now relied upon for choice of whether a SAM can be encoded with LambdaMetafactory or whether to use an AOT compiled anonymous class. Orthogonal to the binary fragilities above, this has the problem of being too restrictive: e.g. scala.PartialOrdering is ineligible for SAM treatment.

Dotty has an extra flag HasInits that tracks the more specific information about constructor side effects.

retronym commented 8 years ago

/cc @adriaanm @smarter

Hat tip to @soc for raising the problem with Ordering

adriaanm commented 8 years ago

We should at least (by RC1) double check that concrete methods no longer give rise to an empty constructor. It's only needed for init statements indeed. Ref #5141