-
Notifications
You must be signed in to change notification settings - Fork 756
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
Type flags are lost when value is transformed via runtime function #9714
Comments
0.14 included an update to the signature of There's a special flag on string parameters that permits "loose" matching, which is why the following will work with Bicep 0.14 or 0.12: param environment string
module mod './module1.bicep' {
name: 'some name'
params: {
env: environment
}
} That flag gets dropped when the parameter is passed to any function, but it shouldn't be. |
By the way, a workaround you can use immediately is the param inputWithEnvSuffix string // e.g. 'something-dev'
var environment = split(inputWithEnvSuffix, '-')[1]
module mod './module1.bicep' {
name: 'some name'
params: {
env: any(environment)
}
} This will update the types used to be equivalent to those in Bicep 0.12, where On our side, we'll look into how/whether to propagate flags through function invocations. |
Thank you for the explanation and workaround! I'll use the |
Notes from the team discussion:
|
@jeskew Thank you again for the detailed follow-up! What you have discussed and noted down totally makes sense in terms of what I would expect from the Bicep type system. 💯 |
Bicep version
Bicep CLI version 0.14.6 (f1dae16)
Describe the bug
Since the latest release (v0.14.6) of the Bicep CLI, type narrowing is being applied when using the
@allowed
decorator on parameters. According to the official docs, these constraints should be applied when an argument is passed into the param.With the recent change (in v0.14.6), the type for the parameter now becomes the union of the literals supplied in the
@allowed
decorator, which makes compilation fail when trying to supply any value that is not one of the exact types present in the union type, even when the value of the argument is actually the correct value.AFAIK there are no ways to cast variables to a specific type (so that we can provide the value as an argument to the parameter with the correct type) which breaks the possibility of using any functions for string manipulation, because the returned type is always
string
, and can thus not be given as an argument to the param.I believe this is an (unintended?) bug, and should be reverted to the previous behaviour of not changing the actual type of the parameter, and instead just apply the constraints during validation of the template.
To Reproduce
Steps to reproduce the behavior:
yields the following error in
main.bicep
:The property "env" expected a value of type "'dev' | 'prod'" but the provided value is of type "string".bicep(BCP036)
Additional context
This worked fine in Bicep CLI version 0.12.1 (e43d137)
The text was updated successfully, but these errors were encountered: