Provide clearer error message when scoped function used in invalid scope
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
**Is your feature request related to a problem? Please describe.**
The following code
```bicep
targetScope='subscription'
var id = resourceGroup().id
```
Produces the following error
> Expected 1 to 2 arguments, but got 0.
However this can be confusing because the same expression `resourceGroup().id` is allowed in other bicep files if they're in a different scope
**Describe the solution you'd like**
I'd expect to error message to be a bit clearer that the expression is not totally invalid - just not suitable for the current context e.g.
> When used in a subscription scope the `resourceGroup` function must provide a resource group name (and optionally a subscription id) "
Similar issues apply in the following
```bicep
targetScope='tenant'
var foo = managementGroup().id
var bar = subscription().id
var baz = resourceGroup()
var bat= resourceGroup('resourceGroupName')
```
```bicep
targetScope='managementGroup'
var bar = subscription().id
var baz = resourceGroup()
var bat= resourceGroup('resourceGroupName')
```
```bicep
targetScope='subscription'
var foo = managementGroup().id
var baz = resourceGroup()
```
```bicep
targetScope= 'resourceGroup'
var foo = managementGroup().id
```
Contributor guide
Research direction
Start by reproducing the listed targetScope and scoped-function expressions to locate the existing argument-count diagnostics. Trace how these cases are analyzed across tenant, management group, subscription, and resource-group scopes; done means invalid uses report the applicable scope context rather than only a generic argument-count error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100