-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
lang: Fix crash in lookup function #19161
Conversation
lang/funcs/collection.go
Outdated
switch { | ||
case ty.IsObjectType(): | ||
if !args[1].IsKnown() { | ||
return args[2].Type(), nil |
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.
Doing this check in here does seem right but I don't think returning the "default" value type here is the right fallback for a couple reasons:
- There might not be a default value (it's optional, and so I think this might cause an out-of-bounds panic)
- Once we do know the key (at apply time) we might find that it matches one of the attributes in
inputMap
after all, and so that'll be the type of our result.
With both of those things in mind, I think the best we can do in this scenario is return cty.DynamicPseudoType, nil
, which effectively means "I don't know yet what the result type will be". That's an okay response when arguments are unknown: it'll just mean we won't catch a type error here during the plan operation. We'll re-run the function again at apply time when we've learned more information, and thus catch any name error there, as usual for unknown values.
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.
That makes sense. I made that change - PTAL.
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.
LGTM, thanks!
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Previously a config like this:
caused a crash:
https://gist.github.com/radeksimko/012c83a42c9f6b647912b62b77e4f8ed