During the instantiation of a generic type A, some other generic
type B may be instantiated multiple times with different parameters.
We can think about each instantiation as a function call that should
temporary bind the parameter names to concrete types. The problem
with the existing implementation in semtypinst was that it was
performing this binding within a shared global table. In this sense,
it was executing the code as a programming language featuring only
global variables. In such a language, re-entrant functions cannot be
defined properly and hence this was leading to problems with similar
types. The solution is simple - just like we need to introduce stack
frames to handle re-entrant functions, we introduce a stack of type
bindings that are pushed and popped during the generic instantiations.
A more efficient implementation is possible by restoring the old
lifting ot tyGenericInvocation to tyGenericInst in liftTypeParam,
but this fix will suffice for now.
fixes#5087fixes#5602fixes#5641fixes#5570
Fixed the dot operator when used within return types (see tgenericdotrettype)
Fixed the matching of generic concepts aliases used with the implicit generics style
Previously it was not possible to use template arguments in template body as
the symbols were not resolved correctly leading to Error: undeclared
identifier: 'XX', eg.:
template defaultOf[T](t: T): expr = (var d: T; d)
echo defaultOf(1) #<- invalid identifier, but should output 0
The problem comes from the fact that macroOrTmpl[...] is transformed by
semSubscript which is trying to evaluate macroOrTmpl identifier in place. This
is okay for non-generic macros or templates, but wrong for generic ones, that
do not have a chance to receive their generic arguments explicitly specified in
brackets.
Solution:
1. macroOrTmpl[...] where macroOrTmpl is non-generic macro or template, then
macroOrTmpl is evaluated before applying brackets. (as before)
2. macroOrTmpl[...] where macroOrTmpl is generic macro or template, then if:
a. It comes from macroOrTmpl[...](...) call expr (efInCall), then macroOrTmpl
is turned into a symbol (efNoEvaluate) rather than evaluating it in place,
then whole bracket expr is returned to semIndirectOp which transforms it
to proper generic macro or template call with explicit generic arguments.
b. macroOrTmpl[...] does not come from call expr, as above macroOrTmpl is
transformed to symbol, then it is transformed into proper generic macro or
template call with explicit generic arguments and no normal arguments.