Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incomplete type checking on object indexers #5045

Open
afscrome opened this issue Nov 1, 2021 · 0 comments
Open

Incomplete type checking on object indexers #5045

afscrome opened this issue Nov 1, 2021 · 0 comments

Comments

@afscrome
Copy link
Contributor

afscrome commented Nov 1, 2021

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

@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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants