|
1 | 1 | ---
|
2 | 2 | title: BCP414
|
3 |
| -description: The spread operator "..." is not permitted in this location. |
| 3 | +description: The `^` indexing operator cannot be used on base expressions of type <base-type>. |
4 | 4 | ms.topic: reference
|
5 | 5 | ms.custom: devx-track-bicep
|
6 | 6 | ms.date: 05/20/2025
|
7 | 7 | ---
|
8 | 8 |
|
9 | 9 | # Bicep diagnostic code - BCP414
|
10 | 10 |
|
11 |
| -This diagnostic occurs when you use expressions to define resource bodies as the [`Spread`](../operator-spread.md) operator gets converted to a function. It's a limitation in JSON. |
| 11 | +This diagnostic occurs when the reverse index operator (^) is used on an expression of an unsupported type, such as object, bool, or int. |
12 | 12 |
|
13 | 13 | ## Description
|
14 | 14 |
|
15 |
| -The spread operator "..." is not permitted in this location. |
| 15 | +The `^` indexing operator cannot be used on base expressions of type \<base-type>. |
16 | 16 |
|
17 | 17 | ## Level
|
18 | 18 |
|
19 | 19 | Error
|
20 | 20 |
|
21 | 21 | ## Examples
|
22 | 22 |
|
23 |
| -The following example raises the diagnostic because the `spread` operator is used to define the resource body: |
| 23 | +The following code attempts to use the ^ operator on an object, which triggers BCP414. |
24 | 24 |
|
25 | 25 | ```bicep
|
26 |
| -param location string = resourceGroup().location |
27 |
| -param addressPrefix string = '10.0.0.0/24' |
28 |
| - |
29 |
| -resource vnet 'Microsoft.Network/virtualNetworks@2024-01-01' = { |
30 |
| - name: 'vnetName' |
31 |
| - location: location |
32 |
| - |
33 |
| - ...(addressPrefix != '' ? { |
34 |
| - properties: { |
35 |
| - addressSpace: { |
36 |
| - addressPrefixes: [ |
37 |
| - addressPrefix |
38 |
| - ] |
39 |
| - } |
40 |
| - } |
41 |
| - } : {}) |
| 26 | +var config = { |
| 27 | + name: 'example' |
| 28 | + value: 42 |
42 | 29 | }
|
| 30 | +
|
| 31 | +output result any = config[^1] // Error: BCP414 - The "^" indexing operator cannot be used on base expressions of type "object". |
43 | 32 | ```
|
44 | 33 |
|
45 |
| -You can fix the diagnostic by using the operator in the lower level: |
| 34 | +To access properties of an object, use the `.` operator instead of `^`. The following code corrects the previous example. |
46 | 35 |
|
47 | 36 | ```bicep
|
48 |
| -param location string = resourceGroup().location |
49 |
| -param addressPrefix string = '10.0.0.0/24' |
50 |
| - |
51 |
| -resource vnet 'Microsoft.Network/virtualNetworks@2024-01-01' = { |
52 |
| - name: 'vnetName' |
53 |
| - location: location |
54 |
| - |
55 |
| - properties: { |
56 |
| - addressSpace: { |
57 |
| - ...(addressPrefix != '' ? { |
58 |
| - addressPrefixes: [ |
59 |
| - addressPrefix |
60 |
| - ] |
61 |
| - } : {}) |
62 |
| - } |
63 |
| - } |
| 37 | +var config = { |
| 38 | + name: 'example' |
| 39 | + value: 42 |
64 | 40 | }
|
| 41 | +
|
| 42 | +output result string = config.name |
65 | 43 | ```
|
66 | 44 |
|
67 | 45 | ## Next steps
|
|
0 commit comments