1

I wan to infer an implicit value of an AppliedType, here's what I've done

val valueType = accessorTree.returnType
val encoderType = tq"DatumEncoder[$valueType]" // returns a Tree
val encoder = c.inferImplicitValue(encoderType) // require a Type

But the tq returns a Tree

How Can I convert it to a Type

jilen
  • 5,633
  • 3
  • 35
  • 84
  • 1
    Did you try `encoderType.tpe`? There are many examples for example for structural types, existential types etc in http://den.sh/quasiquotes.html – Jatin May 05 '14 at 05:15
  • Or you could: `import reflect.runtime.currentMirror import tools.reflect.ToolBox val toolbox = currentMirror.mkToolBox()` and then: `typecheckType(encoderType)` – Jatin May 05 '14 at 05:22
  • @Jatin Can you make an answer. The link is pretty fine!!! I just need such things – jilen May 05 '14 at 05:32

1 Answers1

3

This link contains detailed response for tq types interpolator.

You could just do: encoderType.tpe

Or you could:

import reflect.runtime.currentMirror 
import tools.reflect.ToolBox 
val toolbox = currentMirror.mkToolBox()

def typecheckType(tree: Tree): Type = toolbox.typecheck(tree, toolbox.TYPEmode).tpe
typecheckType(encoderType)
Jatin
  • 31,116
  • 15
  • 98
  • 163