Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vapourise Predef.any2stringadd in interpreter

I am having problem with Predef.any2stringadd that unfortunately is officially considered not a PITA. I changed my API from

trait Foo {
   def +(that: Foo): Foo
}

to a type class approach

object Foo {
   implicit def fooOps(f: Foo): Ops = new Ops(f)
   final class Ops(f: Foo) {
      def +(that: Foo): Foo = ???
   }
}
trait Foo

Now I can hide that horrible method in compiled code like this:

import Predef.{any2stringadd => _}

However, this fails in my REPL/interpreter environment.

val in = new IMain(settings, out)
in.addImports("Predef.{any2stringadd => _}") // has no effect?

How can I tell the interpreter to vapourise this annoying method?

like image 296
0__ Avatar asked Nov 13 '22 15:11

0__


1 Answers

A workaround seems to be to take the implicit conversion out of Foo's companion object, and place it in the top hierarchy (package object in my real case):

object Foo {
//   implicit def fooOps(f: Foo): Ops = new Ops(f)
   final class Ops(f: Foo) {
      def +(that: Foo): Foo = ???
   }
}
trait Foo
implicit def fooOps(f: Foo): Foo.Ops = new Foo.Ops(f)

While I don't know why that should make any difference, it appears it does enough to make the interpreter forget about any2stringadd.

(Still, I think a new ticket should be opened in an attempt to remove that method, also given that string interpolation in Scala 2.10 will make it more superfluous.)

like image 88
0__ Avatar answered Dec 10 '22 21:12

0__