nau
nau

Reputation: 1165

How to get Type of arbitrary tree and check its strong/weak conformance?

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

Upvotes: 0

Views: 66

Answers (1)

nau
nau

Reputation: 1165

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

Upvotes: 2

Related Questions