Skip to content

Suppress shebang directive errors in disabled regions - #86119

Merged
jjonescz merged 1 commit into
dotnet:mainfrom
jjonescz:shebang-disabled-regions
Oct 21, 2026
Merged

jjonescz merged 1 commit into
dotnet:mainfrom
jjonescz:shebang-disabled-regions

Conversation

@jjonescz

@jjonescz jjonescz commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

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

@jjonescz
jjonescz requested a balanced review from Copilot October 19, 2026 11:57
@jjonescz jjonescz added Area-Compilers Feature - Run File #: and #! directives and file-based C# programs labels Oct 19, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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

@RikkiGibson

Copy link
Copy Markdown
Member

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.

@RikkiGibson

RikkiGibson commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

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.

@RikkiGibson RikkiGibson reopened this Oct 19, 2026
@jjonescz
jjonescz marked this pull request as ready for review October 19, 2026 17:19
@jjonescz
jjonescz requested a review from a team as a code owner October 19, 2026 17:19
@AlekseyTs

Copy link
Copy Markdown
Contributor

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.

@AlekseyTs

Copy link
Copy Markdown
Contributor

Done with review pass (commit 1)

@jjonescz

jjonescz commented Oct 20, 2026 •

Copy link
Copy Markdown
Member Author

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.

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.

@jjonescz jjonescz changed the title Ignore shebang directives in disabled regions Suppress shebang directive errors in disabled regions Oct 20, 2026
@jjonescz
jjonescz requested a review from AlekseyTs October 20, 2026 09:24

@AlekseyTs AlekseyTs left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM (commit 1)

@jjonescz
jjonescz merged commit 6d158e8 into dotnet:main Oct 21, 2026
24 checks passed
@jjonescz
jjonescz deleted the shebang-disabled-regions branch October 21, 2026 08:37
@dotnet-policy-service dotnet-policy-service Bot added this to the Next milestone Oct 21, 2026
@akhera99 akhera99 modified the milestones: Next, 18.13 Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-Compilers Feature - Run File #: and #! directives and file-based C# programs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants