Implicit scope resolution

In order to put the implicits in the places where they are required, the compiler first has to find them. This process is called implicit scope resolution and has well-defined rules in order to guarantee that implicits are determined as expected by the language specification and the developer using them. Implicit scope resolution is a three-step process.

Or four-step, if we count the case where the implicit parameter is provided explicitly as an argument to the method. We'll consider this case as number zero and won't take it into the account because it has the highest precedence and does not involve implicit lookup.

We'll provide a short overview of these steps so that we have them in one place for easy reference and then go into the details of each on the list:

  • The current invocation (or lexical) scope. It has precedence over the implicit scope and encloses implicits that are accessible directly by their names without prefix, such as the following:
    • Local declarations
    • Outer scope declarations
    • Package objects
    • Inheritance chain
    • Import statements
  • The implicit scope. It is looked up recursively and includes the following:
    • Companion object of the parameters
    • Companion object of super types
    • Companion object of mixin types (supertraits)
    • Companion object of the type
    • Companion object of the type parameters
    • Companion object of the type constructor
  • Static overloading rules in the case of multiple implicits being found on one of the scopes.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.44.182