Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Obtain the symbol that a "super" call refers to in Scala

I'm writing a Scala compiler plugin for the refchecks phase.

How do I access the symbol that a "super" call refers to, given the symbol of the callsite?

For example, in

trait A {
  def m() {}
}

trait B extends A {
  def m() { super.m() }
}

knowing the symbol for the callsite super.m(), I would like to get the symbol for trait A.

like image 421
amaurremi Avatar asked Nov 12 '22 02:11

amaurremi


1 Answers

I think using of self type annotations and multiple inheritance will serve you:

trait HelperTrait {
  def helperMethod {println("calling helperMethod of HelperTrait")}
}

trait PublicInterface { this: HelperTrait =>
  def useHelperMethod 
  { 
    println("calling useHelperMethod of PublicInterface")
    helperMethod 
  }
}

class ImplementationClass extends PublicInterface with HelperTrait

var obj = new ImplementationClass()
obj.useHelperMethod
obj.helperMethod
like image 130
Mohsen Heydari Avatar answered Nov 15 '22 06:11

Mohsen Heydari