2

I have two classes:

class X[A](implicit ord: Ordering[A]) // + other irrelevant parameters
class Y[A: Ordering] extends X[A]

Given a Symbol corresponding to Y's implicit constructor parameter, I want to find the symbol for the parent class implicit parameter it corresponds to (if one exists).

val yOrdSym = ...
val yOrdType = yOrdSym.typeSignature
val xImplicitParams = 
  xSym.primaryConstructor.paramLists.flatten.
  filter(xParam => xParam.isImplicit && ???)

Now I need to filter it for having the same type as well (or a supertype, but this doesn't matter for my usecase). I've tried xParam.typeSignature =:= yOrdSym.typeSignature, which didn't work. This makes sense, because the type parameters have different owners. However, xParam.typeSignature =:= yOrdSym.typeSignatureIn(xSym.toType) and xParam.typeSignatureIn(ySym.toType) =:= yOrdSym.typeSignature don't work either. How to do it correctly?

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487
  • If I were you, I'd try one of the two approaches: 1) https://github.com/scala/scala/blob/1fbce4612c21a4d0c553ea489b4765494828c09f/src/reflect/scala/reflect/api/Types.scala#L366 passing type parameters from X and Y, 2) stripping off type arguments from typeSignatures and comparing the rest. – Eugene Burmako Mar 27 '16 at 14:13
  • Stripping type arguments doesn't work (e.g. I could have two type parameters with the same context bound in both classes). The first should work, though. – Alexey Romanov Mar 27 '16 at 14:36

0 Answers0