From 20365de1be7633bbb739e6de7052affa346f97f7 Mon Sep 17 00:00:00 2001 From: Charles Stoner Date: Mon, 8 Feb 2021 09:23:08 -0800 Subject: [PATCH 1/3] Document breaking change for #46044 --- .../CSharp/Compiler Breaking Changes - DotNet 6.md | 13 +++++++++++++ .../Compiler Breaking Changes - post VS2019.md | 12 ++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 docs/compilers/CSharp/Compiler Breaking Changes - DotNet 6.md diff --git a/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 6.md b/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 6.md new file mode 100644 index 0000000000000..aa5421c5bc28f --- /dev/null +++ b/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 6.md @@ -0,0 +1,13 @@ +## This document lists known breaking changes in Roslyn in C# 9.0 introduced with .NET 6. + +1. https://github.com/dotnet/roslyn/issues/46044 In C# 9.0 (Visual Studio 16.9), a warning is reported when assigning `default` to, or when casting a possibly `null` value to a type parameter type that is not constrained to value types or reference types. To avoid the warning, the type can be annotated with `?`. + ```C# + static void F1(object? obj) + { + T t1 = default; // warning CS8600: Converting possible null value to non-nullable type + t1 = (T)obj; // warning CS8600: Converting possible null value to non-nullable type + + T? t2 = default; // ok + t2 = (T?)obj; // ok + } + ``` diff --git a/docs/compilers/CSharp/Compiler Breaking Changes - post VS2019.md b/docs/compilers/CSharp/Compiler Breaking Changes - post VS2019.md index 13d1babfe9185..f2f2aa87f5264 100644 --- a/docs/compilers/CSharp/Compiler Breaking Changes - post VS2019.md +++ b/docs/compilers/CSharp/Compiler Breaking Changes - post VS2019.md @@ -142,3 +142,15 @@ class C 22. https://github.com/dotnet/roslyn/issues/49596 In *Visual Studio 2019 version 16.9* and greater, conversions from `sbyte` or `short` to `nuint` require explicit casts, and binary operations with `sbyte` or `short` and `nuint` arguments require explicit casts for one or both operands for `+`, `-`, `*`, `/`, `%`, `<`, `>`, `<=`, `>=`, `==`, `!=`, `|`, `&`, and `^`. + +23. https://github.com/dotnet/roslyn/issues/46044 In *Visual Studio 2019 version 16.9* and greater, a warning is reported when assigning `default` to, or when casting a possibly `null` value to a type parameter type that is not constrained to value types or reference types. To avoid the warning, the type can be annotated with `?`. + ```C# + static void F1(object? obj) + { + T t1 = default; // warning CS8600: Converting possible null value to non-nullable type + t1 = (T)obj; // warning CS8600: Converting possible null value to non-nullable type + + T? t2 = default; // ok + t2 = (T?)obj; // ok + } + ``` From 238f0c7fa0121fc840090bd39fd024b32add7829 Mon Sep 17 00:00:00 2001 From: Charles Stoner Date: Fri, 5 Mar 2021 11:03:41 -0800 Subject: [PATCH 2/3] Rename file --- ...- DotNet 6.md => Compiler Breaking Changes - post DotNet 5.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename docs/compilers/CSharp/{Compiler Breaking Changes - DotNet 6.md => Compiler Breaking Changes - post DotNet 5.md} (100%) diff --git a/docs/compilers/CSharp/Compiler Breaking Changes - DotNet 6.md b/docs/compilers/CSharp/Compiler Breaking Changes - post DotNet 5.md similarity index 100% rename from docs/compilers/CSharp/Compiler Breaking Changes - DotNet 6.md rename to docs/compilers/CSharp/Compiler Breaking Changes - post DotNet 5.md From 0643b45656f0691e8061dd4c13091fbfb70d3aec Mon Sep 17 00:00:00 2001 From: Charles Stoner Date: Fri, 5 Mar 2021 11:06:22 -0800 Subject: [PATCH 3/3] Incorporate feedback --- .../Compiler Breaking Changes - post DotNet 5.md | 2 +- .../Compiler Breaking Changes - post VS2019.md | 12 ------------ 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/docs/compilers/CSharp/Compiler Breaking Changes - post DotNet 5.md b/docs/compilers/CSharp/Compiler Breaking Changes - post DotNet 5.md index aa5421c5bc28f..4ed41c3b0f15a 100644 --- a/docs/compilers/CSharp/Compiler Breaking Changes - post DotNet 5.md +++ b/docs/compilers/CSharp/Compiler Breaking Changes - post DotNet 5.md @@ -1,4 +1,4 @@ -## This document lists known breaking changes in Roslyn in C# 9.0 introduced with .NET 6. +## This document lists known breaking changes in Roslyn after .NET 5. 1. https://github.com/dotnet/roslyn/issues/46044 In C# 9.0 (Visual Studio 16.9), a warning is reported when assigning `default` to, or when casting a possibly `null` value to a type parameter type that is not constrained to value types or reference types. To avoid the warning, the type can be annotated with `?`. ```C# diff --git a/docs/compilers/CSharp/Compiler Breaking Changes - post VS2019.md b/docs/compilers/CSharp/Compiler Breaking Changes - post VS2019.md index f2f2aa87f5264..13d1babfe9185 100644 --- a/docs/compilers/CSharp/Compiler Breaking Changes - post VS2019.md +++ b/docs/compilers/CSharp/Compiler Breaking Changes - post VS2019.md @@ -142,15 +142,3 @@ class C 22. https://github.com/dotnet/roslyn/issues/49596 In *Visual Studio 2019 version 16.9* and greater, conversions from `sbyte` or `short` to `nuint` require explicit casts, and binary operations with `sbyte` or `short` and `nuint` arguments require explicit casts for one or both operands for `+`, `-`, `*`, `/`, `%`, `<`, `>`, `<=`, `>=`, `==`, `!=`, `|`, `&`, and `^`. - -23. https://github.com/dotnet/roslyn/issues/46044 In *Visual Studio 2019 version 16.9* and greater, a warning is reported when assigning `default` to, or when casting a possibly `null` value to a type parameter type that is not constrained to value types or reference types. To avoid the warning, the type can be annotated with `?`. - ```C# - static void F1(object? obj) - { - T t1 = default; // warning CS8600: Converting possible null value to non-nullable type - t1 = (T)obj; // warning CS8600: Converting possible null value to non-nullable type - - T? t2 = default; // ok - t2 = (T?)obj; // ok - } - ```