0

For example, one need to check whether an expression is of whole number type: Byte, Short, Int, Long but not Double or Float. The following code doesn't always work:

case Apply(Select(q, n), List(rhs)) =>
  if (q.tpe.weak_<:<(typeOf[Long])) true else false

For some q their tpe won't be weak conformed even though it has Int type:

a.type weak_<:< Long == false

q.symbol.typeSignature instead of q.tpe works correctly, but not all q have symbol != NoSymbol

nau
  • 1,145
  • 8
  • 20

1 Answers1

2

Instead of q.tpe one should use q.tpe.widen:

case Apply(Select(q, n), List(rhs)) =>
  if (q.tpe.widen.weak_<:<(typeOf[Long])) true else false

Int weak_<:< Long == true
nau
  • 1,145
  • 8
  • 20