Fix regression in assigning BicepValue<T> to properties #53934
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.
Fixes #53862
In general, we are having this issue because when assigning values to ordinary properties and collection items, we are using different approach:
When assigning to ordinary properties, we always copies the value into the current BicepValue.
For instance, when we have a string property, we have this:
in the setter, we call the
Assignmethod which copies whatever we have invalue(which is another BicepValue) into_skuName. In this process, the BicepValue here_skuNamehas its ownSelfto track its reference, and thevaluealso has its ownSelf.In collection case, it is different. When we do this:
We only do this internally:
this will add that BicepValue instance into the list, which might hold a Self of a property, and then we modified its self.
This causes a share of instances between this collection and a property in another instance.
This violates our best practice that we should never share instances. And therefore it is causing the issue.
To fix this, when modifying collections, we must first construct a new
BicepValue<T>instance, and then assign the item value into it, and add our own instance into the list to keep the reference correct, and no longer pollute other properties' self reference.