Skip to content

CS0173: observations and version-change impact #40070

@RexJaeschke

Description

@RexJaeschke

Type of issue

Missing information

Description

Hi there, I'm writing the formal spec for a feature added to V9, for the Ecma Standard. That feature is "Target-Typed Conditional Expression" which is specified by MS here. Although I am using the latest edition of VS for my testing of this feature, I am switching between 8 and 9, so I can see the impact of this new feature.

I am getting the error CS0173; however, your explanation of that revolves entirely around classes while my test does not involve classes, so there are more situations in which this message can arise, and that probably should be documented. Here's my test case:

var x2a = true ? 100 : "ABC";            // V8: CS0173; V9: CS0173

Now consider the following, subtly different, test:

object x1a = true ? 100 : "ABC";     // V8: error CS8957; V9 OK

I suspect that some versions ago, this too might have resulted in CS0173, but that is now "hidden" by CS8957, which says that a feature from a future version is being used, but one that is not available in the current version.

This leads me to the final part of your example:

class M
{
    static int Main ()
    {
        int X = 1;
        // The following line causes CS0173.
        object o = (X == 0) ? null : null;
        return -1;
    }
}

I do not get CS0173! Instead, in V8 I get CS8957, and in V9, it compiles. So you need to rethink just what you are trying to demonstrate here, and you need to factor in the addition of the V9 feature that now allows this to compile. You also need to factor in the addition of nullable reference support in V8, which requires you write object? instead of just object.

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/compiler-messages/cs0173?f1url=%3FappId%3Droslyn%26k%3Dk(CS0173)

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/compiler-messages/cs0173.md

Document Version Independent Id

a02cd93f-30c5-9ada-c252-a17b8425b0cd

Article author

@BillWagner

Metadata

  • ID: 6634ff5d-e8b2-a46f-6a38-169a454b94f1
  • Service: dotnet-csharp
  • Sub-service: errors-warnings

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions