Lazy type resolution for untyped
Note: An unresolved expression is an expression for which no symbol lookups and no type checking have been performed.
Since templates and macros that are not declared as immediate participate in overloading resolution it’s essential to have a way to pass unresolved expressions to a template or macro. This is what the meta-type untyped accomplishes:
template rem(x: untyped) = discard
rem unresolvedExpression(undeclaredIdentifier)
A parameter of type untyped always matches any argument (as long as there is any argument passed to it).
But one has to watch out because other overloads might trigger the argument’s resolution:
template rem(x: untyped) = discard
proc rem[T](x: T) = discard
# undeclared identifier: 'unresolvedExpression'
rem unresolvedExpression(undeclaredIdentifier)
untyped and varargs[untyped] are the only metatype that are lazy in this sense, the other metatypes typed and typedesc are not lazy.
当前内容版权归 nim-lang.org 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 nim-lang.org .