Scala Programming Language
  1. Scala Programming Language
  2. SI-2796

Early Definintion order incorrect if a class extends a trait with Early Definitions

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Out of Scope
    • Affects Version/s: None
    • Fix Version/s: Scala 2.10.0-M4
    • Component/s: Misc Compiler
    • Labels:
      None

      Description

      I didn't get an answer on the list, so I'll raise a bug.

      trait Base {
        val abstractVal: String
        final val useAbstractVal = abstractVal
      }
      
      trait T1 extends {
        val abstractVal = "T1.abstractVal"
      } with Base
       
      class C3 extends T1
       
      assert(new C3().useAbstractVal eq null) // why not == "T1.abstractVal" ?
      
      [[syntax trees at end of icode]]// Scala source: early.scala
      package <empty> {
        abstract trait Base extends java.lang.Object with ScalaObject {
          final <accessor> def Base$$_setter_$$useAbstractVal_=(x$$1: java.lang.String): Unit;
          <stable> <accessor> def abstractVal(): java.lang.String;
          final <stable> <accessor> def useAbstractVal(): java.lang.String
        };
        abstract trait T1 extends java.lang.Object with Base with ScalaObject {
          <accessor> def T1$$_setter_$$abstractVal_=(x$$1: java.lang.String): Unit;
          <stable> <accessor> def abstractVal(): java.lang.String
        };
        class C3 extends java.lang.Object with T1 with ScalaObject {
          <stable> <accessor> def abstractVal(): java.lang.String = C3.this.abstractVal;
          private[this] val abstractVal: java.lang.String = _;
          <accessor> def T1$$_setter_$$abstractVal_=(x$$1: java.lang.String): Unit = C3.this.abstractVal = x$$1;
          final <stable> <accessor> def useAbstractVal(): java.lang.String = C3.this.useAbstractVal;
          private[this] val useAbstractVal: java.lang.String = _;
          final <accessor> def Base$$_setter_$$useAbstractVal_=(x$$1: java.lang.String): Unit = C3.this.useAbstractVal = x$$1;
          def this(): C3 = {
            C3.super.this();
            Base$$class./*Base$$class*/$$init$$(C3.this);
            T1$$class./*T1$$class*/$$init$$(C3.this);
            ()
          }
        };
        abstract trait Base$$class extends  {
          def /*Base$$class*/$$init$$($$this: Base): Unit = {
            $$this.Base$$_setter_$$useAbstractVal_=($$this.abstractVal());
            ()
          }
        };
        abstract trait T1$$class extends  {
          def /*T1$$class*/$$init$$($$this: T1): Unit = {
            val abstractVal: java.lang.String = "T1.abstractVal";
            $$this.T1$$_setter_$$abstractVal_=(abstractVal);
            ()
          }
        }
      }
      

      http://gist.github.com/253684

        Activity

        Hide
        Hubert Plociniczak added a comment -

        Yes, the early definition doesn't work for traits initialization ATM and I guess we should provide it.

        Show
        Hubert Plociniczak added a comment - Yes, the early definition doesn't work for traits initialization ATM and I guess we should provide it.
        Hide
        Jason Zaugg added a comment -

        Until we can fix it, let's issue a warning.

        https://github.com/scala/scala/pull/777

        Show
        Jason Zaugg added a comment - Until we can fix it, let's issue a warning. https://github.com/scala/scala/pull/777
        Hide
        Jason Zaugg added a comment -

        Closing; it seems we're more likely to invest in fully blown trait parameters than into expanding early definitions for traits.

        Show
        Jason Zaugg added a comment - Closing; it seems we're more likely to invest in fully blown trait parameters than into expanding early definitions for traits.

          People

          • Assignee:
            Jason Zaugg
            Reporter:
            Jason Zaugg
            TracCC:
            Ismael Juma
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development