Skip to content

Getting the type for a case class field #15148

Answered by adamw
adamw asked this question in Metaprogramming
Discussion options

You must be logged in to vote

Assuming that tpe is the TypeRepr for the case class, field symbols can be accessed using tpe.typeSymbol.caseFields. Then, to obtain the TypeRepr for a field, you can use .memberType, as follows:

tpe.typeSymbol.caseFields.map { fieldSymbol =>
  val fieldTpe = tpe.memberType(fieldSymbol)
  ...
}

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@adamw

This comment has been hidden.

@bishabosha

This comment has been hidden.

@adamw

This comment has been hidden.

Answer selected by adamw
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants