Repository navigation
Raise error diagnostic on ambiguous scope - #17202
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR improves error handling for ambiguous scope expressions by ensuring that an appropriate diagnostic is raised when a scope cannot be resolved at compile time. Key changes include:
- Adjusting delegate signatures to allow a nullable supplied scope.
- Explicitly returning null after emitting a diagnostic for union types with ambiguous scope.
- Adding a new diagnostic (BCP420) with a corresponding integration test for ambiguous scoping expressions.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/Bicep.Core/Emit/ScopeHelper.cs | Updated delegate signatures and error handling for ambiguous scopes |
| src/Bicep.Core/Diagnostics/DiagnosticBuilder.cs | Added new diagnostic for unresolvable scope expressions (BCP420) |
| src/Bicep.Core.IntegrationTests/ScenarioTests.cs | Added integration test validating the new ambiguous scope diagnostic |
Contributor
|
Test this change out locally with the following install scripts (Action run 15276789134) VSCode
Azure CLI
|
Contributor
Dotnet Test Results 78 files - 39 78 suites - 39 35m 40s ⏱️ - 19m 41s Results for commit 9abcfae. ± Comparison against base commit f2217b9. This pull request removes 1904 and adds 642 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
# Conflicts: # src/Bicep.Core.IntegrationTests/ScenarioTests.cs
Anthony Martin (anthony-c-martin)
approved these changes
May 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Resolves #17157
If a template uses an expression that passes type checking but cannot be understood by
ScopeHelper, the scope is currently silently dropped. This would happen if the expression would evaluate to a union type where each member of the union is a valid scope.Cases where this could happen:
Normally, this would cause a deploy-time error, but some resource (like role assignments) are deployable at all scopes, so rather than having the deployment fail, the resource would deploy at the wrong scope.
Checklist
Microsoft Reviewers: Open in CodeFlow