Skip to content

Avoid assert on erroneous target-typed conditionals - #84752

Merged
jjonescz merged 1 commit into
dotnet:mainfrom
jjonescz:84641-Assert
Aug 5, 2026
Merged

Avoid assert on erroneous target-typed conditionals#84752
jjonescz merged 1 commit into
dotnet:mainfrom
jjonescz:84641-Assert

Conversation

@jjonescz

@jjonescz jjonescz commented Aug 4, 2026

Copy link
Copy Markdown
Member

Fixes #84641.

Microsoft Reviewers: Open in CodeFlow

@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.

Pull request overview

This PR addresses a debug-build crash in C# nullable flow analysis when analyzing certain erroneous conditional (?:) expressions that remain as BoundUnconvertedConditionalOperator (e.g., target-typed conditionals that never get converted due to earlier binding errors). The fix relaxes a Debug.Assert to allow this error case without throwing, and adds a regression test to ensure the compiler reports diagnostics (instead of crashing) for the reported scenario.

Changes:

  • Update a Debug.Assert in NullableWalker to permit unconverted conditional operators that already have errors, avoiding a debug-only failure.
  • Add a regression test covering the reported repro pattern and verifying expected diagnostics.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs Adjusts an assertion to tolerate erroneous unconverted conditionals during nullable analysis without crashing debug builds.
src/Compilers/CSharp/Test/Semantic/Semantics/ConditionalOperatorTests.cs Adds a regression test validating diagnostics for an invalid conditional that previously triggered the debug assertion path.

@jjonescz
jjonescz marked this pull request as ready for review August 4, 2026 16:02
@jjonescz
jjonescz requested a review from a team as a code owner August 4, 2026 16:02
@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.

@jjonescz
jjonescz merged commit 934af28 into dotnet:main Aug 5, 2026
26 checks passed
@jjonescz
jjonescz deleted the 84641-Assert branch August 5, 2026 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debug Build fails with System.InvalidOperationException: _returnTypesOpt is not null || _disableDiagnostics on ToString incorrectly used in ternary

3 participants