Azure / Azure/bicep

Incomplete type checking on object indexers

Open
#5,045 0 comments 0 reactions 0 assignees View on GitHub
type system
Dominant language
Bicep
Stars
3.6k
Forks
830
Avg merge
1d 21m
Merged PRs (30d)
79

Description

**Bicep version**
run `bicep --version` via the Bicep CLI, `az bicep version` via the AZ CLI or via VS code by navigating to the extensions tab and searching for Bicep

**Describe the bug**
When indexing into an object with a string property, type checking doesn't seem to be fully done. In the below repo steps, `foo` the indexer should allow values of type `'One' | 'Two'`, and `Input` is of type `'Three' | 'Four'`. There is no way that `foo[Input]` could ever succeed, so I'd expect the following code to result in a compiler error as there's no way this could result in anything other than a failure

**To Reproduce**

```bicep
@allowed([
'Three'
'Four'
])
param Input string

var foo = {
One: 'Hello'
Two: 'World'
}

var x = foo[Input]
```

**Additional context**
A more interesting variant is when there is the types partially match. (e.g. what if `Input` was of type `'Two' | 'Three' | 'Four'`.) should this continue to be an error, or should it be a warning instead?

Contributor guide

Open the contributing guide

Research direction

Run the provided Bicep reproduction with the Bicep CLI and trace the compiler's object-indexer type checking. Confirm that disjoint indexer and key types are rejected, then determine and test the expected behavior for partially overlapping unions such as 'Two' | 'Three' | 'Four'.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.