[scala] Public implicits are inherited; but protected ones are not?

View: New views
1 Messages — Rating Filter:   Alert me  

[scala] Public implicits are inherited; but protected ones are not?

by Aaron Harnly :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm unclear on whether the following behavior is intentional. I suspect not.

Implicit members with public access are inherited by derived classes.
However, implicit members with *protected* access are not. Eh?

Below is a short script that illustrates the issue; or view the pastie at
http://pastie.textmate.org/private/hvbx0rwsery92y2b6knlxg

// This compiles fine:
trait WithImplicit {
        implicit val t = "foo"
        def showme(implicit t: String) = Console.println(t)
}

object WithInheritedImplicit extends WithImplicit {
        showme
}
WithInheritedImplicit

// The following does not; the only change is the
// addition of the "protected" modifier.

trait WithImplicit {
        protected implicit val t = "foo"
        def showme(implicit t: String) = Console.println(t)
}

object WithInheritedImplicit extends WithImplicit {
  showme
}
WithInheritedImplicit






LightInTheBox - Buy quality products at wholesale price