You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It would be nice to have a typeCheckPattern method in scala.reflect.macros.Context. Right now, none of the existing ways to determine the type of a tree works for patterns:
Invoking the tpe method on a pattern always results in null, using the existing typeCheck function in the Context class throws a TypeCheckException. A full example is attached to this issue.
The text was updated successfully, but these errors were encountered:
@xeno-by said:
The problem here is that typechecking pattern requires a special typechecker mode called PATTERNmode. In fact, there's a bunch of such modes that cover typechecking types, type constructors, super constructor calls, etc. Unfortunately, c.typeCheck works in EXPRmode and doesn't provide a way to customize it.
There are multiple ways to addressing this problem. The first one involves exposing a number of specialized typeCheckXXX methods, e.g. typeCheckExpr, typeCheckType, typeCheckPattern, etc. The second one implies introducing Mode and passing it as a parameter to c.typeCheck. I don't feel very comfortable with either of them (the first one means a bunch of new methods, the second one means another class in the reflection API), so I would like to defer this decision to the reflection API revamp that is supposedly happening in 2.12.
In the meanwhile, you can cast to internal APIs to work around the problem (please note that PATTERNmode requires a non-wildcard expected type - you can get it by typechecking the scrutinee of the pattern match):
It would be nice to have a
typeCheckPattern
method inscala.reflect.macros.Context
. Right now, none of the existing ways to determine the type of a tree works for patterns:Invoking the
tpe
method on a pattern always results innull
, using the existingtypeCheck
function in theContext
class throws aTypeCheckException
. A full example is attached to this issue.The text was updated successfully, but these errors were encountered: