Skip to content

No way to get a TypeRepr directly from a Symbol #13553

Closed
@neko-kai

Description

@neko-kai

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) where tp is a prefix of symbol, or the type of its symbol.owner:

@smarter

if you don't have a specific prefix you care about and want to get the type as seen from its definition, the prefix should be the ThisType of the owner of the symbol

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 through symbol.tree.tpe which may be very costly.

@smarter

and if it's a common enough usecase maybe we should relent and add a tpe method to symbol, if only to steer people away from tree.tpe which could be much more expensive since it can involve unpickling a tree from tasty

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 method def tpe: TypeRepr

/cc @nicolasstucki

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions