From 8732ae96acc28f968908b9c45a84871c375c8587 Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Thu, 7 Nov 2024 09:16:56 -0500 Subject: [PATCH 1/5] Add new diagnostics (#43369) Some compiler diagnostics have been added since the initial feature preview for the C# 13 features. Add those errors and warnings here. Fixes #43289 --- .../compiler-messages/feature-version-errors.md | 5 ++++- .../compiler-messages/inline-array-errors.md | 7 ++++++- .../compiler-messages/ref-modifiers-errors.md | 7 ++++++- .../compiler-messages/ref-struct-errors.md | 7 ++++++- docs/csharp/language-reference/toc.yml | 8 ++++---- 5 files changed, 26 insertions(+), 8 deletions(-) diff --git a/docs/csharp/language-reference/compiler-messages/feature-version-errors.md b/docs/csharp/language-reference/compiler-messages/feature-version-errors.md index db98a8628b4c2..1292bf4b1062e 100644 --- a/docs/csharp/language-reference/compiler-messages/feature-version-errors.md +++ b/docs/csharp/language-reference/compiler-messages/feature-version-errors.md @@ -54,6 +54,7 @@ f1_keywords: - "CS9202" - "CS9211" - "CS9240" + - "CS9260" helpviewer_keywords: - "CS0171" - "CS0188" @@ -107,7 +108,8 @@ helpviewer_keywords: - "CS9202" - "CS9211" - "CS9240" -ms.date: 11/02/2023 + - "CS9260" +ms.date: 11/06/2024 --- # Resolve warnings related to language features and versions @@ -149,6 +151,7 @@ That's be design. The text closely matches the text of the compiler error / warn - **CS9202**: *Feature is not available in C# 12.0. Please use newer language version* - **CS9211**: *The diagnosticId argument to the 'Experimental' attribute must be a valid identifier.* - **CS9240**: *Target runtime doesn't support by-ref-like generics.* +- **CS9260**: *Feature is not available in C# 13.0. Please use newer language version** In addition, the following errors and warnings relate to struct initialization changes in recent versions: diff --git a/docs/csharp/language-reference/compiler-messages/inline-array-errors.md b/docs/csharp/language-reference/compiler-messages/inline-array-errors.md index 49a4e0f1bfabb..d7a2438d26769 100644 --- a/docs/csharp/language-reference/compiler-messages/inline-array-errors.md +++ b/docs/csharp/language-reference/compiler-messages/inline-array-errors.md @@ -16,6 +16,7 @@ f1_keywords: - "CS9183" - "CS9184" - "CS9189" + - "CS9259" helpviewer_keywords: - "CS9164" - "CS9165" @@ -31,7 +32,8 @@ helpviewer_keywords: - "CS9183" - "CS9184" - "CS9189" -ms.date: 11/02/2023 + - "CS9259" +ms.date: 11/06/2024 --- # Resolve errors and warnings with inline array declarations @@ -54,6 +56,7 @@ That's by design. The text closely matches the text of the compiler error / warn - [**CS9183**](#conversions-to-span): *Inline array conversion operator will not be used for conversion from expression of the declaring type.* - [**CS9184**](#inline-array-declaration): *'Inline arrays' language feature is not supported for inline array types with element field which is either a '`ref`' field, or has type that is not valid as a type argument.* - [**CS9189**](#element-access): *`foreach` statement on an inline array of type is not supported* +- [**CS9259**](#inline-array-declaration): *Attribute cannot be applied to a record struct.* ## Inline array declaration @@ -64,6 +67,7 @@ You declare inline arrays as a `struct` type with a single field, and an attribu - **CS9169**: *Inline array struct must declare one and only one instance field which must not be a ref field.* - **CS9180**: *Inline array element field cannot be declared as required, readonly, volatile, or as a fixed size buffer.* - **CS9184**: *'Inline arrays' language feature is not supported for inline array types with element field which is either a '`ref`' field, or has type that is not valid as a type argument.* +- **CS9259**: *Attribute cannot be applied to a record struct.* To fix these arrays, ensure the following are true: @@ -72,6 +76,7 @@ To fix these arrays, ensure the following are true: - The enclosing `struct` has a single instance field, and that instance field is not a `ref` field. - The single instance field is not a fixed size buffer. - The single instance field doesn't include the `required`, `volatile`, or `readonly` modifiers. +- Remove the `record` modifier from your inline array declaration. ## Element access diff --git a/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md b/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md index 437eaae719101..bd5adb8e581e8 100644 --- a/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md +++ b/docs/csharp/language-reference/compiler-messages/ref-modifiers-errors.md @@ -66,6 +66,7 @@ f1_keywords: - "CS9199" - "CS9200" - "CS9201" + - "CS9265" helpviewer_keywords: - "CS0192" - "CS0199" @@ -131,7 +132,8 @@ helpviewer_keywords: - "CS9199" - "CS9200" - "CS9201" -ms.date: 11/02/2023 + - "CS9265" +ms.date: 11/06/2024 --- # Errors and warnings associated with reference parameters, variables, and returns @@ -207,6 +209,7 @@ The following warnings are generated when reference variables are used incorrect - [**CS9198**](#reference-variable-restrictions): *Reference kind modifier of parameter doesn't match the corresponding parameter in target.* - [**CS9200**](#reference-variable-restrictions): *A default value is specified for `ref readonly` parameter, but `ref readonly` should be used only for references. Consider declaring the parameter as `in`.* - [**CS9201**](#reference-variable-restrictions): *Ref field should be ref-assigned before use.* +- [**CS9265**](#reference-variable-restrictions): *Field is never ref-assigned to, and will always have its default value (null reference)* These errors and warnings follow these themes: @@ -261,6 +264,7 @@ The following warnings indicate that a reference variable shouldn't be used, and - **CS9198**: *Reference kind modifier of parameter doesn't match the corresponding parameter in target.* - **CS9200**: *A default value is specified for `ref readonly` parameter, but `ref readonly` should be used only for references. Consider declaring the parameter as `in`.* - **CS9201**: *Ref field should be ref-assigned before use.* +- **CS9265**: *Field is never ref-assigned to, and will always have its default value (null reference)* To fix the error, remove the reference variable where it isn't allowed: @@ -277,6 +281,7 @@ To fix the error, remove the reference variable where it isn't allowed: - Methods attributed with can't use reference parameters. - A Windows runtime event can't be passed as a reference variable. - A `ref readonly` parameter can't have the applied to it in remoting API. +- Initialize a `ref` field in the constructor or as a field initializer. ## `unscoped ref` restrictions diff --git a/docs/csharp/language-reference/compiler-messages/ref-struct-errors.md b/docs/csharp/language-reference/compiler-messages/ref-struct-errors.md index 991b4777132e4..d2f44cf08270d 100644 --- a/docs/csharp/language-reference/compiler-messages/ref-struct-errors.md +++ b/docs/csharp/language-reference/compiler-messages/ref-struct-errors.md @@ -15,6 +15,7 @@ f1_keywords: - "CS9245" - "CS9246" - "CS9247" + - "CS9267" helpviewer_keywords: - "CS8343" - "CS8344" @@ -29,7 +30,8 @@ helpviewer_keywords: - "CS9245" - "CS9246" - "CS9247" -ms.date: 07/30/2024 + - "CS9267" +ms.date: 11/06/2024 --- # Errors and warnings associated with `ref struct` types @@ -46,6 +48,7 @@ ms.date: 07/30/2024 - [**CS9245**](#ref-struct-interface-implementations): *Type cannot implement interface member for `ref struct` type.* - [**CS9246**](#ref-struct-interface-implementations): *A non-virtual instance interface member cannot be accessed on a type parameter that allows ref struct.* - [**CS9247**](#ref-struct-interface-implementations): *foreach statement cannot operate on enumerators of type because it is a type parameter that allows ref struct and it is not known at compile time to implement `IDisposable`.* +- [**CS9267**](#ref-struct-interface-implementations): *Element type of an iterator may not be a ref struct or a type parameter allowing ref structs* ## ref safety violations @@ -74,6 +77,7 @@ Violating any of these rules produces one of the listed errors. If you intended - **CS9245**: *Type cannot implement interface member for `ref struct` type.* - **CS9246**: *A non-virtual instance interface member cannot be accessed on a type parameter that allows ref struct.* - **CS9247**: *foreach statement cannot operate on enumerators of type because it is a type parameter that allows ref struct and it is not known at compile time to implement `IDisposable`.* +- **CS9267**: *Element type of an iterator may not be a ref struct or a type parameter allowing ref structs* Prior to C# 13, [`ref struct`](../builtin-types/ref-struct.md) types can't implement interfaces; the compiler generates *CS8343*. Beginning with C# 13, `ref struct` types can implement interfaces, subject to the following rules: @@ -84,3 +88,4 @@ Beginning with C# 13, a `ref struct` can be used as a type argument for a generi - A `ref struct` is used as a type argument, the type parameter *must* have the `allows ref struct` anti-constraint.- The `allows ref struct` anti-constraint must be last in the `where` clause for that parameter - Uses of instances the type parameter must obey ref safety rules. +- A `ref struct` or a type argument that can be a `ref struct` type can't be used as the element type for an [iterator method](../statements/yield.md). diff --git a/docs/csharp/language-reference/toc.yml b/docs/csharp/language-reference/toc.yml index f4c2d35a5e70e..026c7eb5dff7b 100644 --- a/docs/csharp/language-reference/toc.yml +++ b/docs/csharp/language-reference/toc.yml @@ -437,7 +437,7 @@ items: CS0171, CS0188, CS0843, CS8904, CS1738, CS8022, CS8023, CS8024, CS8025, CS8026, CS8058, CS8059, CS8107, CS8192, CS8302, CS8303, CS8304, CS8305, CS8306, CS8314, CS8320, CS8370, CS8371, CS8400, CS8401, CS8511, CS8627, CS8630, CS8652, CS8703, CS8704, CS8706, CS8773, CS8912, CS8919, CS8929, CS8936, CS8957, CS8967, CS9014, CS9015, CS9016, CS9017, CS9058, CS9064, - CS9103, CS9171, CS9194, CS9202, CS9204, CS9240 + CS9103, CS9171, CS9194, CS9202, CS9204, CS9240, CS9260 - name: Assembly references href: ./compiler-messages/assembly-references.md displayName: > @@ -463,12 +463,12 @@ items: CS7084, CS8166, CS8167, CS8168, CS8169. CS8325, CS8326, CS8327, CS8329, CS8330, CS8331, CS8332, CS8337, CS8338, CS8351, CS8373, CS8374, CS8388, CS8977, CS9072, CS9077, CS9078, CS9079, CS9085, CS9086, CS9087, CS9089, CS9091, CS9092, CS9093, CS9094, CS9095, CS9096, CS9097, CS9101, CS9102, CS9104, CS9190, CS9191, CS9192, CS9193, CS9195, CS9196, CS9197, CS9198, - CS9199, CS9200, CS9201 + CS9199, CS9200, CS9201, CS9265 - name: "`ref struct` types" href: ./compiler-messages/ref-struct-errors.md displayName: > ref struct, - CS8343, CS8344, CS8345, CS9048, CS9050, CS9059, CS9241, CS9242, CS9243, CS9244, CS9245, CS9246, CS9247 + CS8343, CS8344, CS8345, CS9048, CS9050, CS9059, CS9241, CS9242, CS9243, CS9244, CS9245, CS9246, CS9247, CS9267 - name: Iterator methods href: ./compiler-messages/iterator-yield.md displayName: > @@ -503,7 +503,7 @@ items: CS9188, CS9203, CS9208, CS9209, CS9210 - name: Inline arrays href: ./compiler-messages/inline-array-errors.md - displayName: CS9164, CS9165, CS9166, CS9167, CS9168, CS9169, CS9172, CS9173, CS9180, CS9181, CS9182, CS9183, CS9184 + displayName: CS9164, CS9165, CS9166, CS9167, CS9168, CS9169, CS9172, CS9173, CS9180, CS9181, CS9182, CS9183, CS9184, CS9259 - name: Lambda expressions href: ./compiler-messages/lambda-expression-errors.md displayName: > From 8e6c24dc0968d0f4c6b8bb0fdb3b5004b897e471 Mon Sep 17 00:00:00 2001 From: Goswin Rothenthal Date: Thu, 7 Nov 2024 15:27:12 +0100 Subject: [PATCH 2/5] Update fsharp-9.md minor formatting issue (#43361) --- docs/fsharp/whats-new/fsharp-9.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/fsharp/whats-new/fsharp-9.md b/docs/fsharp/whats-new/fsharp-9.md index 9d558ae010205..e8ee076591c75 100644 --- a/docs/fsharp/whats-new/fsharp-9.md +++ b/docs/fsharp/whats-new/fsharp-9.md @@ -120,9 +120,9 @@ Example: type Foo() = member val X : int = 0 with get, set -[<Extension>] +[] type FooExt = - [<Extension>] + [] static member X (f: Foo, i: int) = f.X <- i; f let f = Foo() From a96b3eb7b4b70a631d3ed58b39ded4cbcb061ce2 Mon Sep 17 00:00:00 2001 From: Azure SDK Bot <53356347+azure-sdk@users.noreply.github.com> Date: Thu, 7 Nov 2024 06:27:45 -0800 Subject: [PATCH 3/5] Update package index with latest published versions (#43367) --- docs/azure/includes/dotnet-all.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/azure/includes/dotnet-all.md b/docs/azure/includes/dotnet-all.md index 2ac348a5531e6..948e2ed38b7c4 100644 --- a/docs/azure/includes/dotnet-all.md +++ b/docs/azure/includes/dotnet-all.md @@ -366,8 +366,8 @@ | Unknown Display Name | NuGet [1.0.0](https://www.nuget.org/packages/Azure.AI.ContentSafety.Extension.Embedded.Text/1.0.0)
NuGet [1.0.1-beta.3](https://www.nuget.org/packages/Azure.AI.ContentSafety.Extension.Embedded.Text/1.0.1-beta.3) | | | | Unknown Display Name | NuGet [1.0.0-beta.2](https://www.nuget.org/packages/Azure.Developer.MicrosoftPlaywrightTesting.NUnit/1.0.0-beta.2) | | | | Unknown Display Name | NuGet [1.0.0-beta.2](https://www.nuget.org/packages/Azure.Developer.MicrosoftPlaywrightTesting.TestLogger/1.0.0-beta.2) | | | -| Unknown Display Name | NuGet [1.0.3-preview](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.MySql/1.0.3-preview) | | | -| Unknown Display Name | NuGet [1.0.3-preview](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.MySql/1.0.3-preview) | | | +| Unknown Display Name | NuGet [1.0.4-preview](https://www.nuget.org/packages/Microsoft.Azure.Functions.Worker.Extensions.MySql/1.0.4-preview) | | | +| Unknown Display Name | NuGet [1.0.4-preview](https://www.nuget.org/packages/Microsoft.Azure.WebJobs.Extensions.MySql/1.0.4-preview) | | | | Unknown Display Name | NuGet [1.41.1](https://www.nuget.org/packages/Microsoft.CognitiveServices.Speech.CLI/1.41.1) | | | | Unknown Display Name | NuGet [1.41.1](https://www.nuget.org/packages/Microsoft.CognitiveServices.Speech.Extension.Embedded.SR/1.41.1) | | | | Unknown Display Name | NuGet [1.41.1](https://www.nuget.org/packages/Microsoft.CognitiveServices.Speech.Extension.Embedded.TTS/1.41.1) | | | @@ -571,8 +571,8 @@ | Hyak Common - Tracing Etw | NuGet [1.0.2](https://www.nuget.org/packages/Hyak.Common.Tracing.Etw/1.0.2) | | | | Hyak Common - Tracing Log4Net | NuGet [1.0.2](https://www.nuget.org/packages/Hyak.Common.Tracing.Log4Net/1.0.2) | | | | Microsoft.Azure.SignalR.Emulator | NuGet [1.4.0](https://www.nuget.org/packages/Microsoft.Azure.SignalR.Emulator/1.4.0)
NuGet [1.0.0-preview1-10809](https://www.nuget.org/packages/Microsoft.Azure.SignalR.Emulator/1.0.0-preview1-10809) | | | -| MSBuild | NuGet [0.30.0](https://www.nuget.org/packages/Microsoft.TypeSpec.MSBuild/0.30.0) | | | -| ProviderHub Controller | NuGet [0.16.0](https://www.nuget.org/packages/Microsoft.TypeSpec.ProviderHub.Controller/0.16.0) | | | -| ProviderHub Templates | NuGet [1.8.0](https://www.nuget.org/packages/Microsoft.TypeSpec.ProviderHub.Templates/1.8.0) | | | +| MSBuild | NuGet [0.31.0](https://www.nuget.org/packages/Microsoft.TypeSpec.MSBuild/0.31.0) | | | +| ProviderHub Controller | NuGet [0.17.0](https://www.nuget.org/packages/Microsoft.TypeSpec.ProviderHub.Controller/0.17.0) | | | +| ProviderHub Templates | NuGet [1.9.0](https://www.nuget.org/packages/Microsoft.TypeSpec.ProviderHub.Templates/1.9.0) | | | | Template | NuGet [1.0.2-preview1](https://www.nuget.org/packages/Microsoft.Azure.Template/1.0.2-preview1) | | | | Test HttpRecorder | NuGet [1.13.3](https://www.nuget.org/packages/Microsoft.Azure.Test.HttpRecorder/1.13.3) | | GitHub [1.13.3](https://github.com/Azure/azure-sdk-for-net/tree/mgmt-legacy/sdk/mgmtcommon/TestFramework/Microsoft.Azure.Test.HttpRecorder) | From c47a4a83c581325ba4dfa21d8d76b5d8696d2249 Mon Sep 17 00:00:00 2001 From: Bartosz Klonowski <70535775+BartoszKlonowski@users.noreply.github.com> Date: Thu, 7 Nov 2024 15:28:18 +0100 Subject: [PATCH 4/5] Remove the unused variables after working on CS0077 (#43368) --- docs/csharp/misc/cs0077.md | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/docs/csharp/misc/cs0077.md b/docs/csharp/misc/cs0077.md index e8516b36d8c40..750d8b295f7cc 100644 --- a/docs/csharp/misc/cs0077.md +++ b/docs/csharp/misc/cs0077.md @@ -21,11 +21,7 @@ However, using [pattern matching](../fundamentals/functional/pattern-matching.md ```csharp // CS0077.cs using System; - -class C -{ -} - + struct S { } @@ -34,17 +30,15 @@ class M { public static void Main() { - object o1, o2; - C c; + object o; S s; + + o = new S(); - o1 = new C(); - o2 = new S(); - - s = o2 as S; // CS0077, S is not a reference type + s = o as S; // CS0077, S is not a reference type // Use pattern matching instead of as - if (o2 is S sValue) + if (o is S sValue) { s = sValue; } From 1e08e843311faba4a234198b9f98bb8c0763be2d Mon Sep 17 00:00:00 2001 From: Bill Wagner Date: Thu, 7 Nov 2024 10:21:02 -0500 Subject: [PATCH 5/5] update title and description (#43366) The TOC node and the descriptions could be misleading here. Fixes #43291 Related to dotnet/roslyn#75789 --- docfx.json | 6 +++--- docs/csharp/toc.yml | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docfx.json b/docfx.json index 950167f6b4ac7..2c20057892346 100644 --- a/docfx.json +++ b/docfx.json @@ -791,9 +791,9 @@ "_csharplang/proposals/csharp-13.0/ref-struct-interfaces.md": "This proposal provides features that enable interface authors to allow `ref struct` types to implement a particular interface", "_csharplang/proposals/csharp-13.0/partial-properties.md": "This proposal provides for partial properties and indexers, allowing the definition of a property or indexer to be split across multiple parts.", "_csharplang/proposals/csharp-13.0/overload-resolution-priority.md": "This proposal introduces a new attribute, `OverloadResolutionPriorityAttribute`, that can be applied to methods to influence overload resolution.", - "_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md": "Learn about any breaking changes since the initial release of C# 10", - "_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 8.md": "Learn about any breaking changes since the initial release of C# 11", - "_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 9.md": "Learn about any breaking changes since the initial release of C# 12", + "_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 7.md": "Learn about any breaking changes since the initial release of C# 10 and included in C# 11", + "_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 8.md": "Learn about any breaking changes since the initial release of C# 11 and included in C# 12", + "_roslyn/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 9.md": "Learn about any breaking changes since the initial release of C# 12 and included in C# 13", "_vblang/spec/introduction.md": "This chapter provides and introduction to the Visual Basic language.", "_vblang/spec/lexical-grammar.md": "This chapter defines the lexical grammar for Visual Basic.", "_vblang/spec/preprocessing-directives.md": "This chapter defines the preprocessing directives allowed in Visual Basic", diff --git a/docs/csharp/toc.yml b/docs/csharp/toc.yml index f5bfd4d674be0..540d9e186b7b8 100644 --- a/docs/csharp/toc.yml +++ b/docs/csharp/toc.yml @@ -149,19 +149,19 @@ items: - name: C# 13 displayName: what's New href: whats-new/csharp-13.md - - name: Breaking changes in C# 13 + - name: Breaking changes since C# 12 href: ../../_roslyn/docs/compilers/CSharp/Compiler%20Breaking%20Changes%20-%20DotNet%209.md - name: C# 12 displayName: what's New href: whats-new/csharp-12.md - - name: Breaking changes in C# 12 + - name: Breaking changes since C# 11 href: ../../_roslyn/docs/compilers/CSharp/Compiler%20Breaking%20Changes%20-%20DotNet%208.md - name: C# 11 items: - name: New features displayName: what's new href: whats-new/csharp-11.md - - name: Breaking changes in C# 11 + - name: Breaking changes since C# 10 href: ../../_roslyn/docs/compilers/CSharp/Compiler%20Breaking%20Changes%20-%20DotNet%207.md - name: C# 10 href: whats-new/csharp-10.md