-
Notifications
You must be signed in to change notification settings - Fork 5k
Fix the dictionary indexer issue #50265
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
base: main
Are you sure you want to change the base?
Fix the dictionary indexer issue #50265
Conversation
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.
Pull Request Overview
This PR adds support for symbolic output indexers on Bicep lists and dictionaries, implements the corresponding logic in BicepListOfT
and BicepDictionaryOfT
, and introduces new tests to verify indexing behavior.
- Implemented
_isOutput
branches inthis[int]
andthis[string]
indexers for lists and dictionaries. - Added unit tests for output array and dictionary indexing.
- Updated test files with necessary imports and scaffolding.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
sdk/provisioning/Azure.Provisioning/tests/Expressions/ArrayExpressionTests.cs | Added missing using for Azure.Provisioning.Primitives . |
sdk/provisioning/Azure.Provisioning/tests/BicepValues/BicepValueTests.cs | Added tests for output array/dictionary indexing and test scaffolding. |
sdk/provisioning/Azure.Provisioning/src/BicepListOfT.cs | Added _isOutput branch in list indexer to emit Bicep syntax. |
sdk/provisioning/Azure.Provisioning/src/BicepDictionaryOfT.cs | Refactored dictionary indexer get/set to handle output expressions and prevent invalid assigns. |
Comments suppressed due to low confidence (1)
sdk/provisioning/Azure.Provisioning/tests/BicepValues/BicepValueTests.cs:38
- Add a [Test] attribute above the ValidateLiteralBicepValue method to ensure it is recognized and executed by NUnit.
public void ValidateLiteralBicepValue()
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.
Pull Request Overview
This pull request fixes the dictionary indexer issue by distinguishing between output and input usages for Bicep dictionaries and lists. Key changes include:
- Adding new tests for both output and input scenarios in arrays and dictionaries.
- Modifying BicepListOfT.cs to handle output index access using the resource’s reference.
- Updating BicepDictionaryOfT.cs to conditionally return an indexer expression for output properties and disallow assignments.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
sdk/provisioning/Azure.Provisioning/tests/Expressions/ArrayExpressionTests.cs | Added necessary using directive for primitives. |
sdk/provisioning/Azure.Provisioning/tests/BicepValues/BicepValueTests.cs | Introduced several tests covering output and input scenarios for arrays and dictionaries. |
sdk/provisioning/Azure.Provisioning/src/BicepListOfT.cs | Modified indexer to return an expression when in output mode. |
sdk/provisioning/Azure.Provisioning/src/BicepDictionaryOfT.cs | Updated indexer logic for output properties and ensured assignments are disallowed for expressions and outputs. |
@@ -89,6 +89,10 @@ public BicepValue<T> this[int index] | |||
// can reference their members. | |||
return _referenceFactory!(BicepSyntax.Index(_expression!, BicepSyntax.Value(index))); | |||
} | |||
else if (_isOutput) |
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.
Ensure that _self is never null when _isOutput is true to prevent a potential NullReferenceException; consider adding documentation or an explicit null check.
Copilot uses AI. Check for mistakes.
|
||
set | ||
{ | ||
if (_kind == BicepValueKind.Expression || _isOutput) |
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.
Clarify the behavior in the set accessor by documenting that assignment is disallowed for output properties and when the value kind is an expression, which would help maintain the intended immutability.
Copilot uses AI. Check for mistakes.
Fixes #48491
I think the dictionary we have two different usages.
I think our
BicepDictionary<T>
should support both the purposes.In the issue, that property is an output property. In this issue, we could imply that this dictionary only has the second purpose, and we should split out an indexer expression.
Contributing to the Azure SDK
Please see our CONTRIBUTING.md if you are not familiar with contributing to this repository or have questions.
For specific information about pull request etiquette and best practices, see this section.