If I have the following type
Defn.Var(mods, pats, decltpe, rhs)
in scalameta it might happen that decltype is set to None for a variable like this:
var x = 10
I still want to know the exact type of the variable x which Scala has inferred without checking the type of the assignment expression myself.
I know that I can just get the information that 10 is an Int literal but for more complex expressions it might be helpful to have some helper function for the type.
Is there any function in scalameta which gives you the inferred type?
Scalameta
mostly works with source code (parses it to trees, transforms trees) before its compilation i.e. when there can't be any information about symbols and types. To get information about symbols and types one should start compiler (one of).
This is exactly what SemanticDB is for. If you switch on
semanticdb-scalaccompiler pluginthen upon compilation it will generate
.semanticdbfiles near to.classfiles. Information about symbols and types will be there. These files can be parsed withsemanticdbFor example if you have
App1.scalathen
produces
You can pretty-print this file with
MetapOutput
And
produces
Scheme is here.
Also you can try Scalafix
If you write in
input/src/main/scala/fix/Scalafixdemo.scalaand in
rules/src/main/scala/fix/Scalafixdemo.scalathen it will print
: Inthttps://github.com/DmytroMitin/scalafix-codegen