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
When passing parameters to templates, subsitution may cause the parameter to be evaluated multiple times - warn when this happens
Description
procf(): int=echo"hello"42templatetest(a: int): int=
a + a
echotest(f())
In the above template, a is evaluated twice which may be expensive - in the example, "hello" is printed twice which in most cases is both undesirable and inefficient.
In most cases, it's problem with the template declaration: it should probably have captured a in a local variable.
However, this is only a problem when a evaluates to something non-trivial - ie test(425) is not a problem and should not cause an evaluation warning.
Similarly, sometimes the multi-eval is desired, thus there should be a way to disable the warning locally - test(a{.dirty.}: int) would be one option (or some other keyword) - another option would be a call-site annotation.
Alternatives
No response
Examples
No response
Backwards Compatibility
No response
Links
No response
The text was updated successfully, but these errors were encountered:
Summary
When passing parameters to templates, subsitution may cause the parameter to be evaluated multiple times - warn when this happens
Description
In the above template,
a
is evaluated twice which may be expensive - in the example, "hello" is printed twice which in most cases is both undesirable and inefficient.In most cases, it's problem with the template declaration: it should probably have captured
a
in a local variable.However, this is only a problem when
a
evaluates to something non-trivial - ietest(425)
is not a problem and should not cause an evaluation warning.Similarly, sometimes the multi-eval is desired, thus there should be a way to disable the warning locally -
test(a{.dirty.}: int)
would be one option (or some other keyword) - another option would be a call-site annotation.Alternatives
No response
Examples
No response
Backwards Compatibility
No response
Links
No response
The text was updated successfully, but these errors were encountered: