Skip to content

CS9058 compiler (but not doc) message can be misleading #54739

Description

@RexJaeschke

Type of issue

Missing information

Description

The following code compiles under V12:

class C;
struct S;
interface I;
enum E;

which allows bodies of these declarations to be omitted.

However, when compiled with earlier versions, each results in CS9058.

Now the on-line docs for this error say

CS9058: Feature is not available in C# xx. Please use language version 12 or greater.

which is correct. However, the message reported by the compiler is, as follows:

[CS9058] Feature 'Primary constructors' is not available in language C# xx. Please use language version 12 or greater.

This is misleading, as there are no primary constructors being used here. It's just that the MS spec for the primary constructor feature smuggled in the ability to omit these bodies. So, a better compiler message would be helpful.

Page URL

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

Content source URL

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

Document Version Independent Id

b75d77df-8629-28f8-bc46-b8bc1a4b8ab1

Platform Id

17463722-03e9-8158-01e2-2da0991a1564

Article author

@BillWagner

Metadata

  • ID: 46e75de6-8d41-b986-5f95-67a1149c6d8c
  • PlatformId: 17463722-03e9-8158-01e2-2da0991a1564
  • Service: dotnet-csharp
  • Sub-service: errors-warnings

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions