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

Narrow object types when assigned value is not an object literal or variable reference #12798

Merged
merged 5 commits into from
Jan 4, 2024

Conversation

jeskew
Copy link
Contributor

@jeskew jeskew commented Dec 19, 2023

Resolves #12590

The TypeValidator's object type narrowing logic currently only runs when the assigned value is or can be traced directly back to an object literal (i.e., an ObjectSyntax node). This PR updates the narrowing logic for both object and discriminated objects to be type- rather than syntax-driven, which allows narrowing to be performed on the return value of expressions, property/array accesses, and references to resources, module outputs, and imported variables.

Microsoft Reviewers: Open in CodeFlow

@jeskew jeskew changed the title Jeskew/12590 Narrow object types when assigned value is not an object literal or variable reference Dec 19, 2023
Copy link
Contributor

github-actions bot commented Dec 19, 2023

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

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

Copy link
Contributor

github-actions bot commented Dec 19, 2023

Test Results

    65 files   -     34      65 suites   - 34   24m 6s ⏱️ - 31m 44s
10 468 tests  -     12  10 468 ✅  -     12  0 💤 ±0  0 ❌ ±0 
25 431 runs   - 12 705  25 431 ✅  - 12 705  0 💤 ±0  0 ❌ ±0 

Results for commit d861cbc. ± Comparison against base commit df7406b.

♻️ This comment has been updated with latest results.

@jeskew jeskew marked this pull request as ready for review December 19, 2023 17:08
@jeskew jeskew requested a review from a team January 3, 2024 16:00
@jeskew jeskew enabled auto-merge (squash) January 4, 2024 15:43
@jeskew jeskew merged commit e77a133 into main Jan 4, 2024
44 checks passed
@jeskew jeskew deleted the jeskew/12590 branch January 4, 2024 16:01
anthony-c-martin pushed a commit that referenced this pull request Feb 9, 2024
…s an additional properties type (#13272)

Resolves #13247 

The type narrowing on objects introduced in #12798 will erroneously
raise a missing property diagnostic if the assigned value does not have
an explicit property defined for each of the target's required
properties, even if the assigned value allows additional properties.
This PR updates the type narrowing to consider required properties not
to be missing if the assigned value allows arbitrary additional
properties.
###### Microsoft Reviewers: [Open in
CodeFlow](https://microsoft.github.io/open-pr/?codeflow=https://github.com/Azure/bicep/pull/13272)
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