ayvango
ayvango

Reputation: 5977

How to remove/rename definition from current scope?

How could I rename definition from the current scope? The encouraging example:

package fails {
  trait A
  object Inner {
    import A => AA // error here
    trait B
    trait A extends AA with B
  }
}

The code with separate packages works but it looks like boilerplate:

package works {
  package boilerplate {
    trait A
  }
  import boilerplate._

  object Inner {
    import boilerplate.{A => AA}
    trait B
    trait A extends AA with B
  }
}

How could it be written elegantly?

Upvotes: 0

Views: 43

Answers (1)

Jeffrey Chung
Jeffrey Chung

Reputation: 19517

Make a slight adjustment:

package works {
  trait A
  object Inner {
    import works.{A => AA}
    trait B
    trait A extends AA with B
  }
}

Upvotes: 1

Related Questions