-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sem: fix type inference for static
parameters
#1433
sem: fix type inference for static
parameters
#1433
Conversation
The evaluated expression now contains conversions, fixing typing problems with empty container expressions and also making sure converters are taken into account.
It's now taken care of in a unified manner by the new `tyStatic` late evaluation.
This is necessary for the original expression to be replaced with their evaluated-to value. The remaining macro/template static inlining in `sigmatch` thus becomes obsolete.
Without it, empty container types wouldn't be patched up properly. Instead of doing this in `sigmatch`, the new `tryEvalStaticArgument` procedure is added to `sem` and made available to `sigmatch` via `PContext`. It applies the post-match fitting plus the `tyStatic` wrapping.
The new ones cover `static` parameters.
The test would have previously failed, as `sigmatch` previously looked for a `float` -> `static int` converter.
The failure of |
Only the no-environment form is handled, as closures with an environment shouldn't be able to leave compile-time evaluation in the first place.
Restructure the type creation a bit, with the goal of making it easier to follow.
Use `fitNode` to restore the implicit conversion, which makes sure that an error is reported in case there's a type mismatch (only possible in macro-generated AST).
For making
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the this solution, where semexprs
handles nkClosure
is better as it's less action at a distance (compared to vmserdes
), and full nkClosure
analysis would be built into sem
, likely involving semexprs
anyhow.
/merge |
Merge requested by: @saem Contents after the first section break of the PR description has been removed and preserved below:
|
Summary
static
parameters
static T
parameter values not being of typeT
, when theargument is not directly of type
T
but requires a conversionstatic
parameters
Details
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 theformal
tyStatic
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 havingthe wrong type
Solution
If the formal type is a
static T
, full argument matching (includingimplicit conversion and converter handling) for between the argument
and
T
is performed first, and only in case of success is theexpression compile-time evaluated, and the resulting
tyStatic
typebound 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 staticarguments.
The new
static
handling renders the macro/templatestatic
special-casing obsolete; replacing the
static
argument with the evaluationresult is now done in
evalTemplateArgs
.Typed AST
For calls to routines with
static
arguments, the typed argumentexpression now stays in the AST as-is, instead of being replaced with
the evaluated value.