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

Preserve distinction between {} and object in compiled JSON #13597

Merged
merged 2 commits into from Mar 13, 2024
Merged

Conversation

jeskew
Copy link
Contributor

@jeskew jeskew commented Mar 12, 2024

Resolves #13556

Given an object type declaration with no catchall schema, the type checker will issue warnings if a property whose name does not match any property declarations is supplied.

param example { foo: string } = { bar: 'string' }         // <-- Issues a BCP037 warning because there is no known `bar` property

@sealed()
param sealedExample { foo: string } = { bar: 'string' }   // <-- Issues a BCP037 error because there is no known `bar` property and the object is sealed

This means that given an object type declaration of {}, all supplied properties will trigger a BCP037 warning because an empty object was expected. This behaves differently from the untyped object object, which matches without warning against any object. The distinction between {} and object was getting dropped when templates were compiled to JSON, however, because the compiler wasn't including any information in the type definition that would allow the two to be distinguished; instead, they would both be compiled to {"type": "object"}.

This PR updates the compiler to include an empty properties constraint on object type declarations that include no properties so that it can tell the difference between {} and object when loading or importing from JSON modules.

Microsoft Reviewers: Open in CodeFlow

Copy link
Contributor

github-actions bot commented Mar 12, 2024

Test this change out locally with the following install scripts (Action run 8269011137)

VSCode
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-vsix.sh) --run-id 8269011137
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-vsix.ps1) } -RunId 8269011137"
Azure CLI
  • Mac/Linux
    bash <(curl -Ls https://aka.ms/bicep/nightly-cli.sh) --run-id 8269011137
  • Windows
    iex "& { $(irm https://aka.ms/bicep/nightly-cli.ps1) } -RunId 8269011137"

@jeskew jeskew closed this Mar 12, 2024
@jeskew jeskew reopened this Mar 12, 2024
Copy link
Contributor

github-actions bot commented Mar 12, 2024

Test Results

    65 files   -     34      65 suites   - 34   23m 2s ⏱️ - 16m 24s
10 683 tests  -     17  10 681 ✅  -     17  2 💤 ±0  0 ❌ ±0 
25 256 runs   - 12 615  25 252 ✅  - 12 613  4 💤  - 2  0 ❌ ±0 

Results for commit 591bd06. ± Comparison against base commit 0c0394b.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@shenglol shenglol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@jeskew jeskew merged commit 148466a into main Mar 13, 2024
44 checks passed
@jeskew jeskew deleted the jeskew/13556 branch March 13, 2024 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants