Azure / Azure/bicep

decompile uses concat function instead of string interpolation

Open
#8,881 3 comments 0 reactions 0 assignees View on GitHub
devdiv story: decompiler
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
v0.12.1

**Describe the bug**
When decompiling a JSON that uses the `concat` function, using the function in bicep causes https://aka.ms/bicep/linter/prefer-interpolation

**To Reproduce**
This template produces the following bicep output.
```json
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"variables": {
"var1": "TestVar"
},
"outputs": {
"testOutput": {
"type": "string",
"value": "[if(equals('true', 'true'), concat(resourceGroup().name, add(1,1), variables('var1')), '')]"
}
}
}
```

```bicep
var var1 = 'TestVar'

output testOutput string = (('true' == 'true') ? concat(resourceGroup().name, (1 + 1), var1) : '')
```

**Additional context**
The above decompile produces static analysis issues which can be automatically fixed by Visual Studio. I do not think we should produce any errors which can be automatically fixed.
```bicep
var var1 = 'TestVar'

output testOutput string = (('true' == 'true') ? '${resourceGroup().name}${(1 + 1)}${var1}' : '')
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the decompile flow with the JSON template shown in the issue and inspect how the concat expression is emitted in the resulting Bicep output. Compare the output with the interpolation form in the issue and verify that the generated code no longer triggers the prefer-interpolation linter warning.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, json
Domain
cloud, compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.