-
Notifications
You must be signed in to change notification settings - Fork 780
Raise error diagnostic on ambiguous scope #17202
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Test this change out locally with the following install scripts (Action run 15276789134) VSCode
Azure CLI
|
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
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