Closed zerbina closed 3 months ago
The failure of tgeneric_various.nim
is due to proc symbols passed to static[proc()]
parameters now being turned into closures (as they should). The evaluated result is an nkClosure
, however, which can currently not pass through sem
again.
For making static[proc()]
parameters work again, I've added handling for nkClosure
to semExpr
-- nkClosure
AST is now turned back into an nkHiddenStdConv
. I think it's an okay solution for now; the alternatives would have been to either:
nkClosure
nkSym
node in vmcompilerserdes
/merge
Merge requested by: @saem
Contents after the first section break of the PR description has been removed and preserved below:
## Notes for Reviewers * the typed argument expression staying in the typed AST makes #1192 a bit easier
Summary
static
parametersstatic T
parameter values not being of typeT
, when the argument is not directly of typeT
but requires a conversionstatic
parametersDetails
When matching an expression against a formal parameter that:
static
parameterstatic
type somewhere (e.g.,int or static[float]
)the expression was compile-time evaluated first, and on success, assigned a
tyStatic
type. If thetyStatic
argument type matched the formaltyStatic
type, the argument type was bound to the formaltyStatic
as-is.In case an implicit conversion is necessary, the conversion was applied only after the evaluated
tyStatic
was bound to the parameter type, leading to:static
parameter having the wrong typeSolution
If the formal type is a
static T
, full argument matching (including implicit conversion and converter handling) for between the argument andT
is performed first, and only in case of success is the expression compile-time evaluated, and the resultingtyStatic
type bound to the parameter type.Post-match fitting has to take place prior to const evaluation (in order to correctly type empty aggregates), so a new procedure
tryEvalStaticArgument
is introduced that handles the static arguments.The new
static
handling renders the macro/templatestatic
special- casing obsolete; replacing thestatic
argument with the evaluation result is now done inevalTemplateArgs
.Typed AST
For calls to routines with
static
arguments, the typed argument expression now stays in the AST as-is, instead of being replaced with the evaluated value.