Fix #4270: Emit BCP180 error for nested getSecret() instead of crashing#19258
Open
jiangmingzhe wants to merge 1 commit intoAzure:mainfrom
Open
Fix #4270: Emit BCP180 error for nested getSecret() instead of crashing#19258jiangmingzhe wants to merge 1 commit intoAzure:mainfrom
jiangmingzhe wants to merge 1 commit intoAzure:mainfrom
Conversation
43521bf to
1d9f672
Compare
…rashing
Previously, when getSecret() was used inside nested objects in module
parameters (e.g., params: { config: { secret: kv.getSecret('x') } }),
the compiler would crash with NotImplementedException during emit
instead of validating the placement during semantic analysis.
This fix adds validation logic in FunctionPlacementValidatorVisitor to
detect when getSecret() is nested inside object structures by:
- Walking up the syntax tree from the function call
- Counting ObjectSyntax nodes between the property and params boundary
- Allowing 0 levels of nesting for params, 1 for extensionConfigs
- Emitting BCP180 diagnostic for invalid nested cases
The ARM template schema only supports KeyVault references at the top
parameter level (as { reference: {...} }), not nested within value
objects, so this validation prevents generating invalid ARM templates.
Added comprehensive test coverage:
- Nested objects at various depths (2-3 levels)
- Nested objects in loops and ternary expressions
- Nested objects inside arrays
- All existing tests continue to pass (valid cases unaffected)
Fixes Azure#4270
1d9f672 to
9bcf264
Compare
shenglol
reviewed
Mar 30, 2026
| x.syntax is ObjectPropertySyntax ops && | ||
| ops.TryGetKeyText() is string key && | ||
| (string.Equals(key, LanguageConstants.ModuleParamsPropertyName, LanguageConstants.IdentifierComparison) || | ||
| string.Equals(key, LanguageConstants.ModuleExtensionConfigsPropertyName, LanguageConstants.IdentifierComparison))); |
Contributor
There was a problem hiding this comment.
Would looking up the property by name still work if the parameter or extension config contains an object that itself has a property named params or extensionConfigs? For example:
module foo 'foo.bicep' = {
params: {
myParam: {
params: { // <-- this could be mistaken for the top-level `params` due to the name
}
}
}
}Maybe instead we can first locate the module declaration syntax and then use that to find the top-level params / extensionConfigs object within its body. If we go this route, I think we wouldn’t need to filter syntaxRecorder to get the target ancestors list above.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, when getSecret() was used inside nested objects in module parameters (e.g., params: { config: { secret: kv.getSecret('x') } }), the compiler would crash with NotImplementedException during emit instead of validating the placement during semantic analysis.
This fix adds validation logic in FunctionPlacementValidatorVisitor to detect when getSecret() is nested inside object structures by:
The ARM template schema only supports KeyVault references at the top parameter level (as { reference: {...} }), not nested within value objects, so this validation prevents generating invalid ARM templates.
Added comprehensive test coverage:
Fixes #4270
Description
Example Usage
Checklist
Microsoft Reviewers: Open in CodeFlow