Azure / Azure/bicep

Add overloading for user-defined functions

Open
#14,184 0 comments 4 reactions 0 assignees View on GitHub
enhancement
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 2h
Merged PRs (30d)
79

Description

Suggested by @pmalarme in https://github.com/Azure/bicep/discussions/14183

Originally posted by **pmalarme** May 28, 2024
User-defined function is an amazing feature of Bicep. It makes it easy to implement naming convention across all Bicep modules for example.

Function overloading would lead to a cleaner like I could write a function. For example, I'm implementing a function to get / generate the name of a resource. I put some parameters that could be null:
```bicep
func getResourceName(resourceType resourceTypeType, workload string, env string, region string, instance string?) => ...
```
If I don't use the instance, I need to call it like this:
```bicep
param resourceGroupName string = getResourceName('resourceGroup', 'my-workload', 'dev', 'gwc', null)
```

If I could overload function, I would have defined 2 functions:
```bicep
func getResourceName(resourceType resourceTypeType, workload string, env string, region string, instance string?) => ...

func (resourceType resourceTypeType, workload string, env string, region string) => ...
```

Therefore I can call now this function like this:
```bicep
param resourceGroupName string = getResourceName('resourceGroup', 'my-workload', 'dev', 'gwc')
```

Contributor guide

Open the contributing guide

Research direction

Start with the user-defined function syntax and overload examples in the issue, then locate the Bicep entry points for function definitions and calls. Establish supported overload syntax, resolution behavior, diagnostics, and test coverage before implementation; done means valid overloads work and ambiguous or invalid calls are handled consistently.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.