Azure / bicep

Bicep is a declarative language for describing and deploying Azure resources
MIT License
3.25k stars 754 forks source link

Add operator (+) should support strings and compile to concat function #1488

Open miqm opened 3 years ago

miqm commented 3 years ago

Is your feature request related to a problem? Please describe. To improve building strings and perhaps enable multi-line experience similar to one that is present in C#, we could use + sign to concatenate strings.

Describe the solution you'd like Currently expression var x = 'a' + 'b' gives error, while it could be compiled to concat function.

majastrz commented 3 years ago

We originally planned to implement the operator this way. Unfortunately, the type information we have available is not 100% reliable and we didn't want subtle changes to expressions cause the + operator to be compiled differently, possibly causing runtime errors. As a general rule, none of the operators are allowed to do type-directed translation. (Each operator has an unconditional 1:1 correspondence with some function.)

The solution for this would be to add a new function to the runtime that combines the behavior of concat and add and the bicep + operator would compile into that always.

ucheNkadiCode commented 2 years ago

@majastrz and @alex-frankel do you think we can close this and label our string interpolation as a viable alternative?

alex-frankel commented 2 years ago

I think we can leave it open. I don't think it's high priority, but I can see it eventually being added.

stan-sz commented 2 years ago

I wonder if this would also cover https://github.com/Azure/bicep/issues/4153#issuecomment-943361638