Skip to content
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

Index from end operator ([^]) #16104

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

Conversation

jeskew
Copy link
Contributor

@jeskew jeskew commented Jan 13, 2025

Resolves #10104

Currently blocked pending rollout of ARM w4+

This PR adds a new [^] operator that accesses an element of an array counting from the end rather than the start. The syntax and semantics match those of the C# "hat" operator.

When used in conjunction with the .? (safe dereference) operator in an array index, the ? should precede the ^, e.g., myArray[?^1] will retrieve the last item in myArray unless myArray is empty, in which case the expression will return null.

Microsoft Reviewers: Open in CodeFlow

@jeskew jeskew added the do not merge Do not merge this pull request yet. label Jan 13, 2025
# Conflicts:
#	src/Bicep.Core.Samples/Files/baselines/Modules_CRLF/main.ir.bicep
#	src/Bicep.Core.Samples/Files/baselines/Modules_CRLF/main.json
#	src/Bicep.Core.Samples/Files/baselines/Modules_CRLF/main.symbolicnames.json
#	src/Bicep.Core.Samples/Files/baselines/Modules_CRLF/main.syntax.bicep
#	src/Bicep.Core/Emit/ExpressionConverter.cs
Copy link
Contributor

github-actions bot commented Jan 13, 2025

Test this change out locally with the following install scripts (Action run 12836590865)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 12836590865
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 12836590865"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 12836590865
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 12836590865"

Copy link
Contributor

github-actions bot commented Jan 13, 2025

Dotnet Test Results

    78 files   -     39      78 suites   - 39   34m 54s ⏱️ - 16m 21s
11 675 tests  -     16  11 675 ✅  -     16  0 💤 ±0  0 ❌ ±0 
27 082 runs   - 13 506  27 082 ✅  - 13 506  0 💤 ±0  0 ❌ ±0 

Results for commit 4e561db. ± Comparison against base commit 756fa60.

This pull request removes 1861 and adds 658 tests. Note that renamed tests count towards both.

		nestedProp1: 1
		nestedProp2: 2
		prop1: true
		prop2: false
	1
	2
	\$'")
	prop1: true
	prop2: false
…
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
�ӽ\u000e�0\u0010\u0007��>E�\u0003���\u001c������\u0000\u0015Έ\u0011$�	���-�q���ab�c{I�����7�\u0016M�U�d����ظ\u0015*ջ�\u0011
��7N8h
��v�Nz���T��9��A2���r�\u0005\u0004`\u0007�A0\u001dh�e��{�ОX��4�8+Rl٥�\u0015]y>T��5�\u0001��M�D���\u0003E��QR+!\u0001\u0008\u000fuh�Hg����A�C�m�I��\u000e�#Vކ�̵��ҽ9��8�y\u0001���Y\u0000\u000c\u0000\u0000,"Value cannot be null. (Parameter 'source')")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
��K\u000e�0\u0010\u0006�=\u0005'(3c����K��(��P\u000c�@b��ea�\u0002�\u0006��~������/��w�9\u0016u#)�\u0014K17�\u0012�F�\u0007�Q ��\u0000֚����;\u0019�6�Ծ�%��A�FƝ�"G�2*\u0006\u0006��(�p�k��\u001aF7�Nyk��ꬼ4�\u001d\u0016�S\u000b�>h0����uE��\u000f@��\u0016EZ!q��j��"�����\u001fkw\u0010\u0004A\u0010��	J0��\u0000\u000c\u0000\u0000,"The path: index.json was not found in artifact contents")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000
��O\u000b�0\u0014\u0000��\u0014�\u000f0���,�\u0010t�\u0008\u000b��1r��\u0016j ��DtQ��'h��ރ��퍸;U���u^\u0010�K�\u0012�5jxB4�ט\u0000���"
R\u0002B�꼒\u0006��T�)e��~\u0010��*�T\u0007\u000c�`\u001aA�\u0011I�d\u0014&&vj��\u0019���\u001c$Y�+r)�Y�����}L�ŧ��]ѷ��\ �^\u0004��q\u0000D���\u000f2��>�\u000f'�\u000e�M�<���șc�\u0003�]�eY�տ'����\u0000\u000c\u0000\u0000,"'7' is an invalid end of a number. Expected a delimiter. Path: $.INVALID_JSON | LineNumber: 0 | BytePositionInLine: 20.")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003�Խ
�0\u0010\u0007��>E�\u0003Ĥ�$���Ep�\u0001b{b���V(��n;�K�K?\u0004�\u001bs\u0007w!���{�l�&XVL*_�\u0019\u0019\u001boi���\u0000C�y�\u001b�4!�\u0019}�\u001e���e��\u001c�~�\u001fP[�\u0019F�H#@�\u0002��RC`Vm-\u001e���\u0016�>Gi�`�.�-�ڳ�����\u000c���t3��K �\u001f\u0000�\u0002��'\+��?K&�<�\u000f�\u001drl
�kLv�\u001d��6�d�\u0015>���q\u001cǙ�\u000bPN%�\u0000\u000c\u0000\u0000,"Value cannot be null. (Parameter 'source')")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003�Խ
�0\u0010\u0007��>E�\u0003����P���`E� �J�\u0005+�J[��˛\u000e�Rt�`~c��.������*�IZV�\u0017\z��\u0019\u0012��\u0005\u0008\u0004�\u000b#L	�\u0008q��7�p�j]�UƘ���tt��i\u0008�W�2\u0000�L\u0005ܟ�ʩ�\u0002�s��9̊$m襺\u0016ms��<�\u0005���o8܌o�g\u001c	�B.\u0010\u0018r¤@a�?J&�<�\u000f7�\u000f�M�<���؝;�\u0007�z'˲,kxOip/�\u0000\u000c\u0000\u0000,"'7' is an invalid end of a number. Expected a delimiter. Path: $.INVALID_JSON | LineNumber: 0 | BytePositionInLine: 20.")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Bicep_compiler_handles_corrupted_extension_package_gracefully (\u001f�\u0008\u0000\u0000\u0000\u0000\u0000\u0000\u0003���
�0\u000c\u0007�}�=A��i���=�
E\u0007~�N��\u0003���\u000e��
/s\u0013��\u0010�R�2ݹn��C^�R\u001beS)�\u0006�%\u001a��Р@~\u0001\u0001lBE$��\u000ch��U�9v� �N\s*�\u000cY3�ݠ�\u001a\u0008��U��G{�\]s�Z�����s]�~�\u0018\u001bX��Ѡ���֎O�\u0007P\u0002�I\u0019B�>��8���L�y�/��(���\u0004�S\$\u0000\u000c\u0000\u0000,"The path: index.json was not found in artifact contents")
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = mcr.microsoft.com, RepositoryPath = unknown/path/az, ExtensionVersion = 0.0.0-placeholder },Azure.RequestFailedException: The artifact does not exist in the registry.
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138,[(BCP192, Error, Unable to restore the artifact with reference "br:mcr.microsoft.com/unknown/path/az:0.0.0-placeholder": The artifact does not exist in the registry.)])
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = mcr.microsoft.com, RepositoryPath = unknown/path/az, ExtensionVersion = 0.0.0-placeholder },Azure.RequestFailedException: The artifact does not exist in the registry.
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138,[(BCP192, Error, Unable to restore the artifact with reference "br:mcr.microsoft.com/unknown/path/az:0.0.0-placeholder": The artifact does not exist in the registry.)])
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = unknown.registry.azurecr.io, RepositoryPath = bicep/extensions/az, ExtensionVersion = 0.0.0-placeholder },System.AggregateException: Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443))
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 51
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/AzureContainerRegistryManager.cs:line 63
   at Bicep.Core.Registry.OciArtifactRegistry.TryRestoreArtifactAsync(RootConfiguration configuration, OciArtifactReference reference) in /home/runner/work/bicep/bicep/src/Bicep.Core/Registry/OciArtifactRegistry.cs:line 495,[(BCP192, Error, Unable to restore the artifact with reference "br:unknown.registry.azurecr.io/bicep/extensions/az:0.0.0-placeholder": Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)))])
Bicep.Core.IntegrationTests.AzTypesViaRegistryTests ‑ Repository_not_found_in_registry (ArtifactRegistryAddress { RegistryAddress = unknown.registry.azurecr.io, RepositoryPath = bicep/extensions/az, ExtensionVersion = 0.0.0-placeholder },System.AggregateException: Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443))
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 51
   at Bicep.Core.Registry.AzureContainerRegistryManager.DownloadManifestAndLayersAsync(IOciArtifactReference artifactReference, ContainerRegistryContentClient client) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 138
   at Bicep.Core.Registry.AzureContainerRegistryManager.<>c__DisplayClass4_0.<<PullArtifactAsync>g__DownloadManifestInternalAsync|0>d.MoveNext() in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 44
--- End of stack trace from previous location ---
   at Bicep.Core.Registry.AzureContainerRegistryManager.PullArtifactAsync(RootConfiguration configuration, IOciArtifactReference artifactReference) in D:\a\bicep\bicep\src\Bicep.Core\Registry\AzureContainerRegistryManager.cs:line 63
   at Bicep.Core.Registry.OciArtifactRegistry.TryRestoreArtifactAsync(RootConfiguration configuration, OciArtifactReference reference) in D:\a\bicep\bicep\src\Bicep.Core\Registry\OciArtifactRegistry.cs:line 495,[(BCP192, Error, Unable to restore the artifact with reference "br:unknown.registry.azurecr.io/bicep/extensions/az:0.0.0-placeholder": Retry failed after 4 tries. Retry settings can be adjusted in ClientOptions.Retry or by configuring a custom retry policy in ClientOptions.RetryPolicy. (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)) (No such host is known. (unknown.registry.azurecr.io:443)))])
…

♻️ This comment has been updated with latest results.

# Conflicts:
#	src/Bicep.Core.IntegrationTests/UserDefinedTypeTests.cs
@jeskew jeskew force-pushed the jeskew/index-from-end-operator branch 3 times, most recently from 70b36aa to 32c8b4f Compare January 17, 2025 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge Do not merge this pull request yet.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Indexing arrays from the end
1 participant