title: Call class contructor before trait's constructor in scala
body: <p>I have this scenario</p>
  
  <pre><code>trait D {
      def someMethod(): Unit = {}
    }
  
    trait C {
      val locations: Seq[Int]
  
      someSomethingWithLocations() // calling this in constructor
  
      def someSomethingWithLocations(): Unit = {
        print(locations.length)
      }
    }
  
    class B extends D with C {
      override val locations: Seq[Int] = 1 :: 2 :: 3 :: Nil
      someMethod()
    }
  
    def main(args: Array[String]): Unit = {
      val b = new B
    }
  </code></pre>
  
  <p>When I run this code <code>someSomethingWithLocations</code> throws null pointer exception because constructor of class B is not called yet, hence locations is not initialized.
  And If I change declaration of class B to </p>
  
  <pre><code>      class B extends{
          override val locations: Seq[Int] = 1 :: 2 :: 3 :: Nil
          someMethod()
        } with D with C 
  </code></pre>
  
  <p>compiler complains that someMethod() is not found. How can i resolve this issue?</p>
  
  <p>For now I have moved declaration of locations to a different trait and my program works as expected but I would like to avoid unnecessary trait if possible.</p>