Is it possible to get the type of a variable after the refchecks phase in a compiler plugin

I am making a compiler plugin after the “refchecks” phase and I need to access the types of the parameters in a called method.
E.g. if the code is:
myDog.bark(false)
I would need to get that the parameter passed to bark is a Boolean.

However when going through the tree, if I do showRaw on the parameter I get:
Literal(Constant(false))

Is there a way that I can get the type of false easily? I am amenable to changing the phase at which my plugin runs if that helps.

If Literal(Constant(false)) is a tree do tree.tpe or tree.tpe.widen. This should be Boolean(false) (singleton type) or Boolean correspondingly.
showRaw(tree.tpe) and showRaw(tree.tpe.widen) will be FoldableConstantType(Constant(false)) and TypeRef(ThisType(scala), scala.Boolean, List()) correspondingly.
Type info is available after typer phase, so refchecks is ok https://typelevel.org/scala/docs/phases.html

1 Like

Thanks! The tree.tpe worked just fine.