Skip to content

Mixin: fix the initialization of traits #578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2015

Conversation

smarter
Copy link
Member

@smarter smarter commented May 16, 2015

Before this commit, the following code:

trait Hello {
  println("Hello")
  val x: Int = 1
  println("World")
}

Became:

<trait> trait Hello extends Object {
  def <init>(): Hello = {
    {
      ()
    }
    this
  }
  <accessor> def x(): Int
  protected def initial$x(): Int = {
    println("Hello")
    1
  }
}

Notice that the initialization statements after the last getter were
missing, this is now fixed:

<trait> trait Hello extends Object {
  def <init>(): Hello = {
    {
      println("World");
      ()
    }
    this
  }
  <accessor> def x(): Int
  protected def initial$x(): Int = {
    println("Hello")
    1
  }
}

Review by @odersky

@scala-jenkins
Copy link

Can one of the admins verify this patch?

Before this commit, the following code:
trait Hello {
  println("Hello")
  val x: Int = 1
  println("World")
}

Became:
<trait> trait Hello extends Object {
  def <init>(): Hello = {
    {
      ()
    }
    this
  }
  <accessor> def x(): Int
  protected def initial$x(): Int = {
    println("Hello")
    1
  }
}

Notice that the initialization statements after the last getter were
missing, this is now fixed:
<trait> trait Hello extends Object {
  def <init>(): Hello = {
    {
      println("World")
      ()
    }
    this
  }
  <accessor> def x(): Int
  protected def initial$x(): Int = {
    println("Hello")
    1
  }
}
@smarter
Copy link
Member Author

smarter commented May 21, 2015

Rebased.

DarkDimius added a commit that referenced this pull request May 22, 2015
Mixin: fix the initialization of traits
@DarkDimius DarkDimius merged commit 91bb668 into scala:master May 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants