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
function: Don't call function Impl if we didn't call Type
By default cty function calls "short circuit" -- skip calling the Type
function and just immediately return cty.DynamicPseudoType -- if any of
the arguments are cty.DynamicVal.
However, in that case we were previously only skipping the call to Type
but yet still expecting Impl to be able to run. That's incorrect because
Impl functions should be able to treat Type as a "guard" and be guaranteed
that Impl will never run if Type failed.
To fix that hole we'll now track whether we skipped calling Type, and if
so we'll also skip calling Impl and just immediately return an unknown
value. Individual functions can still opt out of this behavior by
declaring on or more of their parameters as AllowDynamicType: true, in
which case their own Type function will get to decide how to handle that
situation.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+8Lines changed: 8 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,11 @@
1
+
# 1.13.1 (Unreleased)
2
+
3
+
*`function`: If a function parameter that doesn't declare `AllowDynamicType: true` recieves a `cty.DynamicVal`, the function system would previously just skip calling the function's `Type` callback and treat the result type as unknown. However, the `Call` method was then still calling a function's `Impl` callback anyway, which violated the usual contract that `Type` acts as a guard for `Impl` so `Impl` doesn't have to repeat type-checking already done in `Type`: it's only valid to call `Impl` if `Type` was previosly called _and_ it succeeded.
4
+
5
+
The function system will now skip calling `Impl` if it skips calling `Type`, immediately returning `cty.DynamicVal` in that case. Individual functions can opt out of this behavior by marking one or more of their parameters as `AllowDynamicType: true` and then handling that situation manually inside the `Type` and `Impl` callbacks.
6
+
7
+
As a result of this problem, some of the `function/stdlib` functions were not correctly handling `cty.DynamicVal` arguments after being extended to support refinements in the v1.13.0 release, causing unexpected errors or panics when calling them. Those functions are fixed indirectly by this change, since their callbacks will no longer run at all in those cases, as was true before they were extended to support refinements.
0 commit comments