Repository navigation
Suppress shebang directive errors in disabled regions - #86119
Conversation
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
There was a problem hiding this comment.
🔵 Needs a closer look
Targeted test results and fail-before/pass-after regression evidence remain unverified.
No open issues 🎉
What changed in this PR
Extends disabled-region handling to shebang directives in Roslyn’s C# parser, following the earlier ignored-directive fix.
Changes:
- Suppresses shebang placement and project-type diagnostics in inactive regions.
- Adds tests covering nested inactive regions, script/feature configurations, preserved trivia, and diagnostics after reactivation.
The change is narrowly scoped; execution-based regression validation remains unverified.
| File | Description |
|---|---|
| src/Compilers/CSharp/Test/Syntax/Parsing/IgnoredDirectiveParsingTests.cs | Adds inactive-region and reactivation regression tests. |
| src/Compilers/CSharp/Portable/Parser/DirectiveParser.cs | Restricts shebang diagnostics to active regions. |
Review effort: Balanced
|
Yes it feels like in any ignored region, it could be that what we are "temporarily" seeing as a directive, is actually inside a multi-line string, and, therefore reporting a diagnostic on it still doesn't make sense. |
|
Thanks for fixing this! edit: oops, I guess GitHub makes ctrl+shift+enter "close pull request" in the main comment box. Very annoying since the muscle memory to leave a code comment without "starting a review" is also ctrl+shift+enter. |
|
From my perspective, the nature of the changes doesn't correspond to stated intent of the PR ("Ignore shebang directives in disabled regions"). Given that, I am not sure whether the title is inaccurate, or the implementation doesn't follow the intent. |
|
Done with review pass (commit 1) |
Previously a shebang in a disabled region would result in an error: #if false
#!test
#endif(error CS9378: '#!' must be the first characters on the first line of the file) with this PR, it's not an error anymore. I guess the title can be more specific in that we are not ignoring the directives, but their errors; will update, thanks. |
Follow up on #78158.
Technically we could probably do this for all directives, but "ignored directives" (
#:and#!) are the easiest to justify this for - they are ignored, after all.Microsoft Reviewers: Open in CodeFlow