Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 7, 2025

The CS0173 compiler error documentation was outdated and focused exclusively on class conversions, missing important information about C# 9's target-typed conditional expressions feature. This update addresses several issues:

Key Problems Fixed:

  • Documentation claimed CS0173 only occurred with classes, but it can happen with any types
  • Missing information about how C# 9's target-typed conditional expressions changed the behavior
  • Outdated example with object o = (X == 0) ? null : null; that no longer produces CS0173
  • No explanation of when CS8957 appears instead of CS0173 in different C# versions

Examples of the Issue:

// Still causes CS0173 in all versions (no target type with var)
var result = true ? 100 : "ABC";            

// Now works in C# 9+ due to target-typed conditional expressions  
object result = true ? 100 : "ABC";         // C# 8: CS8957, C# 9+: OK

Changes Made:

  • Updated main description to cover all types, not just classes
  • Added comprehensive explanation of C# 9 target-typed conditional expressions
  • Replaced outdated examples with accurate, tested scenarios
  • Added version-specific guidance for C# 8 vs C# 9+ behavior
  • Included proper nullable reference type syntax (object?)
  • Added note explaining when CS8957 appears instead of CS0173

The documentation now accurately reflects modern C# compiler behavior and provides clear guidance for resolving CS0173 across different language versions.

Fixes #40070.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.


Internal previews

📄 File 🔗 Preview link
docs/csharp/language-reference/compiler-messages/cs0173.md Compiler Error CS0173

Copilot AI changed the title [WIP] CS0173: observations and version-change impact Update CS0173 documentation for C# 9 target-typed conditional expressions Aug 7, 2025
Copilot AI requested a review from BillWagner August 7, 2025 19:41
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

This is a great start @copilot, but I have some things for you to address.

Copilot AI requested a review from BillWagner August 7, 2025 20:36
Copy link
Member

@BillWagner BillWagner left a comment

Choose a reason for hiding this comment

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

This is ready for final review.

@BillWagner BillWagner marked this pull request as ready for review August 7, 2025 20:47
@BillWagner BillWagner requested a review from a team as a code owner August 7, 2025 20:47
@BillWagner BillWagner requested a review from adegeo August 7, 2025 20:47
Co-authored-by: Genevieve Warren <[email protected]>
@BillWagner BillWagner enabled auto-merge (squash) August 8, 2025 20:52
@BillWagner BillWagner merged commit 765e0cb into main Aug 8, 2025
10 checks passed
@BillWagner BillWagner deleted the copilot/fix-40070 branch August 8, 2025 20:55
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.

CS0173: observations and version-change impact

3 participants