-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to get a TypeRepr
directly from a Symbol
#13553
Comments
Shouldn't it be possible to build a
Maybe name the method |
Quick (and dirty?) draft: e986a97 As workaround for // p : a method parameter Symbol
p.tree match {
case n: ValDef =>
val t: TypeRepr = n.tpt.tpe
println(s"param = $n / type = ${n.tpt.tpe}")
case _ => // KO
} |
This seems to be linked with #9707 |
Compiler version
3.1.0-RC1
Gist
Inspired by the discussion in https://gitter.im/scala/contributors?at=613e981df3449e13a46d2ea3, the recommended way to get a TypeRepr of a Symbol is to use
tp.memberType(symbol)
wheretp
is a prefix of symbol, or the type of itssymbol.owner
:@smarter
However, when we don't have a prefix type already at hand, there's no way to get a TypeRepr of the owner of the symbol - there are no methods that return
TypeRepr
on the Symbol! So the only way is throughsymbol.tree.tpe
which may be very costly.@smarter
I think that would be the best outcome, it's a common enough usecase in my experience, and there's actually no way to get the ThisType of the owner of the symbol to do it the proper way and avoid tree parsing.
Expectation
Expected
Symbol
to have a methoddef tpe: TypeRepr
/cc @nicolasstucki
The text was updated successfully, but these errors were encountered: