Compiler bug fixed?

First, a brief description. It seems that if I put the implicit for some other type in the companion object and import it into the scope of the class, it will not be found during implicit resolution until it is explicitly specified once (or defined above the class). An example is below.

class A(val a: Something) object A { implicit val default = ... //found by default } object B { def func(fn: => T)(implicit a: A) = ... } class Broken { def doSomething = { import Broken._ // or Broken.actual B.func { ... } // Uses A.default, not Broken.actual for implicit } } object Broken { implicit val actual = ... } class Fixed { def doSomething = { import Fixed._ println(actual) //reference actual B.func { ... } // uses Fixed.actual } } object Fixed { implicit val actual = ... } object WTF { implicit val actual = ... } class WTF { def doSomething = { import WTF._ B.func { ... } // With object definition first this works without referencing actual } } 

I kind of assume that at the moment I found a compiler error, so I will open jira against Scala, but at the same time I am wondering if anyone knows if this is expected, or if you already have an open error?

edit: https://issues.scala-lang.org/browse/SI-7830

edit2: Deleted an ad of type ": A" from all the actual and default values ​​to correctly recreate my problem.

+4
source share
1 answer

Sorry, this is β€œindicated” to the extent that the specification exists. "Specification" is buried in the comments of the ticket from five years ago. https://issues.scala-lang.org/browse/SI-801

+3
source

Source: https://habr.com/ru/post/1501519/


All Articles