Closed
Description
The following compiles, but shouldn't,
object Test {
import implicits.Not
class Foo
class Bar
implicit def foo: Foo = ???
implicitly[Foo]
implicitly[Not[Foo]] // compiles, but shouldn't
implicitly[Not[Bar]] // compiles, correctly
}
It also appears that the following traditional negation as failure encoding of Not
works as it would in Scala 2,
final class Not2[T] private ()
trait LowPriorityNot2 {
/** A fallback method used to emulate negation in Scala 2 */
implicit def default[T]: Not2[T] = Not2.value.asInstanceOf[Not2[T]]
}
object Not2 extends LowPriorityNot2 {
/** A value of type `Not` to signal a successful search for `Not[C]` (i.e. a failing
* search for `C`). A reference to this value will be explicitly constructed by
* Dotty's implicit search algorithm
*/
def value: Not2[Nothing] = new Not2[Nothing]()
/** One of two ambiguous methods used to emulate negation in Scala 2 */
implicit def amb1[T](implicit ev: T): Not2[T] = ???
/** One of two ambiguous methods used to emulate negation in Scala 2 */
implicit def amb2[T](implicit ev: T): Not2[T] = ???
}
object Test {
class Foo
class Bar
implicit def foo: Foo = ???
implicitly[Foo]
implicitly[Not2[Foo]] // does not compile, as expected under Scala 2 ambiguity rules
implicitly[Not2[Bar]] // compiles
}