Skip to content

Commit 7d3d960

Browse files
authored
Merge pull request #300104 from mumian/0520-bcp076
Document bcp076
2 parents c9d05d8 + 9c7a6b2 commit 7d3d960

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

articles/azure-resource-manager/bicep/bicep-core-diagnostics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Bicep warnings and error codes
33
description: Understand Bicep warnings and error codes.
44
ms.topic: conceptual
55
ms.custom: devx-track-azurecli, devx-track-bicep, devx-track-arm-template
6-
ms.date: 03/25/2025
6+
ms.date: 05/20/2025
77
---
88

99
# Bicep core diagnostics
@@ -81,7 +81,7 @@ If you need more information about a particular diagnostic code, select the **Fe
8181
| <a id='BCP073' />[BCP073](./diagnostics/bcp073.md) | Error/Warning | The property \<property-name> is read-only. Expressions can't be assigned to read-only properties. |
8282
| <a id='BCP074' />BCP074 | Error | Indexing over arrays requires an index of type "{LanguageConstants.Int}", but the provided index was of type "{wrongType}". |
8383
| <a id='BCP075' />BCP075 | Error | Indexing over objects requires an index of type "{LanguageConstants.String}", but the provided index was of type "{wrongType}". |
84-
| <a id='BCP076' />BCP076 | Error | Can't index over expression of type "{wrongType}". Arrays or objects are required. |
84+
| <a id='BCP076' />[BCP076](./diagnostics/bcp076.md) | Error | Can't index over expression of type \<wrong-type>. Arrays or objects are required. |
8585
| <a id='BCP077' />[BCP077](./diagnostics/bcp077.md) | Error/Warning | The property \<property-name> on type \<type-name> is write-only. Write-only properties can't be accessed. |
8686
| <a id='BCP078' />[BCP078](./diagnostics/bcp078.md) | Error/Warning | The property \<property-name> requires a value of type \<type-name>, but none was supplied. |
8787
| <a id='BCP079' />BCP079 | Error | This expression is referencing its own declaration, which isn't allowed. |
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
title: BCP076
3+
description: Can't index over expression of type <wrong-type>. Arrays or objects are required.
4+
ms.topic: reference
5+
ms.custom: devx-track-bicep
6+
ms.date: 05/20/2025
7+
---
8+
9+
# Bicep diagnostic code - BCP076
10+
11+
This diagnostic occurs when attempting to use the index operator ([] or [^index]) on an expression that isn't an array or object. This happens when the expression being indexed is of an incompatible type, such as a string, integer, boolean, or null.
12+
13+
## Description
14+
15+
Can't index over expression of type \<wrong-type>. Arrays or objects are required.
16+
17+
## Level
18+
19+
Error
20+
21+
## Examples
22+
23+
The following code attempts to index a string, which triggers BCP076:
24+
25+
```bicep
26+
var notAnArray = 'hello'
27+
var invalidAccess = notAnArray[0] // Error: BCP076 - Can't index over expression of type 'hello'. Arrays or objects are required.
28+
```
29+
30+
This code tries to use the reverse index operator on an integer:
31+
32+
```bicep
33+
var number = 42
34+
var invalidIndex = number[^1] // Error: BCP076 - Can't index over expression of type '42'. Arrays or objects are required.
35+
```
36+
37+
To fix the error, ensure the expression is an array or object:
38+
39+
```bicep
40+
var sizes = ['small', 'medium', 'large']
41+
var first = sizes[0] // Returns 'small'
42+
var last = sizes[^1] // Returns 'large'
43+
44+
var settings = { key1: 'value1', key2: 'value2' }
45+
var value = settings['key1'] // Returns 'value1'
46+
```
47+
48+
If you need to extract parts of a string, use string functions like [split](../bicep-functions-string.md#split) or [substring](../bicep-functions-string.md#substring):
49+
50+
```bicep
51+
var text = 'hello'
52+
var chars = split(text, '') // Returns ['h', 'e', 'l', 'l', 'o']
53+
var firstChar = chars[0] // Returns 'h'
54+
```
55+
56+
## Next steps
57+
58+
For more information about Bicep diagnostics, see [Bicep core diagnostics](../bicep-core-diagnostics.md).

articles/azure-resource-manager/bicep/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,8 @@ items:
663663
href: diagnostics/bcp072.md
664664
- name: BCP073
665665
href: diagnostics/bcp073.md
666+
- name: BCP076
667+
href: diagnostics/bcp076.md
666668
- name: BCP077
667669
href: diagnostics/bcp077.md
668670
- name: BCP078

0 commit comments

Comments
 (0)