user3995789
user3995789

Reputation: 3460

scala import package object without package name

How does this code work?

PackageObject.scala

package lila

object makeTimeout {
  implicit val large = 5
}

Socket.scala

package lila.socket

import makeTimeout.large

lila.socket package imports makeTimeout.large, but it doesn't use lila.makeTimeout.large.

Upvotes: 2

Views: 255

Answers (1)

Iulian Dragos
Iulian Dragos

Reputation: 5712

It doesn't, but your minimized example is different from the original code.

In the original code makeTimeout is defined inside a trait WithPlay, and that's later inherited by the package object lila, defined in package.scala, and that makes makeTimeout a member of package lila.

Note that you could make your code compile if you broke down the package declaration in two lines:

package lila
package socket

Upvotes: 3

Related Questions