scala-debug-adapter icon indicating copy to clipboard operation
scala-debug-adapter copied to clipboard

[Scala 3] Evaluation of local method or local class in a value class

Open adpi2 opened this issue 2 years ago • 0 comments

Problem

The evaluation of a local method or a local class in a value class is currently not supported.

package example

class A(self: String) extends AnyVal:
  def m(size: Int): String =
    class B:
      def m(): String =
        self.take(size)
    val b = new B
=>    b.m()
$ b.m()
Cannot evaluate because of failed compilation:
-- Error: <expression>:1:3 -----------------------------------------------------
1 |b.m()
  |^^^^^
  |Evaluation involving a local method or local class in a value class not supported:
  |method m belongs to class B which is local inside value class A.

More failing tests can be found here and here.

Details

The problem is that the symbol of a local class or local method is lost somewhere between the extract-expression and resolve-reflect-eval phases. The compiler creates new symbols for them that we don't know how to find. We may need to take action in the compiler to fix this. Also the captured this has a different name, since it is the this of the value class, not the one of its companion object.

adpi2 avatar Jun 14 '22 08:06 adpi2