diff --git a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs index b4b5e8bb3784cc9962ca8242d33ddd976b90a095..7aa4a9f9afb007989d540610de0c4bfabd1bbde3 100644 --- a/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs +++ b/src/Compilers/CSharp/Portable/FlowAnalysis/NullableWalker.cs @@ -1596,6 +1596,14 @@ private static BoundExpression SkipReferenceConversions(BoundExpression possibly return possiblyConversion; } + // https://github.com/dotnet/roslyn/issues/30140: Track nullable state from ??=. + public override BoundNode VisitNullCoalescingAssignmentOperator(BoundNullCoalescingAssignmentOperator node) + { + var result = base.VisitNullCoalescingAssignmentOperator(node); + SetResult(node); + return result; + } + public override BoundNode VisitNullCoalescingOperator(BoundNullCoalescingOperator node) { Debug.Assert(!IsConditionalState); diff --git a/src/Compilers/CSharp/Portable/LanguageVersion.cs b/src/Compilers/CSharp/Portable/LanguageVersion.cs index ec46ca42cee28201b52fca3955a1e774be2c7c5f..ed7b32f9b9e6ff30517188970840b83904c71da0 100644 --- a/src/Compilers/CSharp/Portable/LanguageVersion.cs +++ b/src/Compilers/CSharp/Portable/LanguageVersion.cs @@ -332,9 +332,9 @@ public static LanguageVersion MapSpecifiedToEffectiveVersion(this LanguageVersio switch (version) { case LanguageVersion.Latest: - return LanguageVersion.CSharp8; + return LanguageVersion.CSharp7_3; case LanguageVersion.Default: - return LanguageVersion.CSharp8; + return LanguageVersion.CSharp7; default: return version; } diff --git a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs index 63a6d6f75d39af896cbc112306e790836f21a43f..27ad5b5cddf502bf4653d6432fe5da42bc8ed258 100644 --- a/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs +++ b/src/Compilers/CSharp/Portable/Operations/CSharpOperationFactory.cs @@ -273,6 +273,7 @@ private IOperation CreateInternal(BoundNode boundNode) case BoundKind.RefValueOperator: case BoundKind.Sequence: case BoundKind.StackAllocArrayCreation: + case BoundKind.SuppressNullableWarningExpression: case BoundKind.TypeExpression: case BoundKind.TypeOrValueExpression: diff --git a/src/Compilers/CSharp/Portable/Symbols/Synthesized/InjectedNonNullTypesAttributeSymbol.cs b/src/Compilers/CSharp/Portable/Symbols/Synthesized/InjectedNonNullTypesAttributeSymbol.cs index ee2951a912439ca20ea8d24577ea6cf1b1716f35..41f5bf767bd102246b5ff2979614bf7ac217b676 100644 --- a/src/Compilers/CSharp/Portable/Symbols/Synthesized/InjectedNonNullTypesAttributeSymbol.cs +++ b/src/Compilers/CSharp/Portable/Symbols/Synthesized/InjectedNonNullTypesAttributeSymbol.cs @@ -36,7 +36,7 @@ ImmutableArray makeConstructor(CSharpCompilation compilation, Name Binder.ReportUseSiteDiagnostics(boolType, diagnostics, Location.None); var boolWithAnnotations = TypeSymbolWithAnnotations.Create(boolType); - // PROTOTYPE constructor should save the parameter into a field (for users of reflection) + // PROTOTYPE(NullableReferenceTypes): Constructor should save the parameter into a field (for users of reflection) return ImmutableArray.Create( new NonNullTypesAttributeConstructorSymbol( containingType, diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index 0868522cfab3976a23afa8e07c5d27ae51bdd7e6..9c824c93391e9c84a9671fab618d3a291f5fa77a 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -1000,8 +1000,8 @@ namespace NotMicrosoft.CodeAnalysis { } ((NamespaceSymbol)comp.SourceModule.GlobalNamespace.GetMember("Microsoft.CodeAnalysis")).GetMembers().Single().ToTestDisplayString()); } - // PROTOTYPE Test emitting netmodule (we'll won't inject NNT) - // PROTOTYPE test script + // PROTOTYPE(NullableReferenceTypes): Test emitting netmodule (we won't inject NNT) + // PROTOTYPE(NullableReferenceTypes): Test script [Theory] [InlineData(NonNullTypesTrue)] @@ -7359,7 +7359,7 @@ partial class C1 { } }"; var compilation = CreateCompilation(new[] { source, NonNullTypesTrue }); - // PROTOTYPE(NullReferenceTypes): What nullability is getting emitted? + // PROTOTYPE(NullableReferenceTypes): What nullability is getting emitted? compilation.VerifyDiagnostics( // (16,18): warning CS8611: Nullability of reference types in type of parameter 'x' doesn't match partial method declaration. // partial void M1(T? x, T[]? y, System.Action z, System.Action?[]? u) where T : class @@ -7492,7 +7492,7 @@ partial class C1 { } }"; var compilation = CreateCompilation(new[] { source }); - // PROTOTYPE(NullReferenceTypes): Missing WRN_MissingNonNullTypesContextForAnnotation for '?' in + // PROTOTYPE(NullableReferenceTypes): Missing WRN_MissingNonNullTypesContextForAnnotation for '?' in // (17,18): // partial void M1(T? x, T[]? y, System.Action z, System.Action?[]? u) where T : class compilation.VerifyDiagnostics( @@ -8187,7 +8187,7 @@ class CL1 { } ", NonNullTypesTrue }); - // PROTOTYPE(NullReferenceTypes): Should report WRN_NullReferenceAssignment for `ref x3` + // PROTOTYPE(NullableReferenceTypes): Should report WRN_NullReferenceAssignment for `ref x3` // even though the local is unassigned. (The local should be treated as an l-value for assignment.) c.VerifyDiagnostics( // (12,12): warning CS8604: Possible null reference argument for parameter 'p' in 'void C.M1(CL1 p)'. @@ -25276,7 +25276,7 @@ class CL1 } } ", NonNullTypesTrue }); - // PROTOTYPE(NullReferenceTypes): Should report WRN_NullReferenceAssignment for `x7--` + // PROTOTYPE(NullableReferenceTypes): Should report WRN_NullReferenceAssignment for `x7--` // even though the local is unassigned. (The local should be treated as an l-value for assignment.) c.VerifyDiagnostics( // (10,21): warning CS8604: Possible null reference argument for parameter 'x' in 'CL0 CL0.operator ++(CL0 x)'. diff --git a/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs b/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs index c309bd813460fca6f0601f34bdf4d837c7132313..1cbfd927fe0f3e565fb15a8f81755171de1a0132 100644 --- a/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs @@ -288,7 +288,7 @@ public class B var countedTree = new CountedSyntaxTree(foreignType); - var compilation = CreateCompilation(new SyntaxTree[] { underlyingTree, countedTree }); + var compilation = CreateCompilation(new SyntaxTree[] { underlyingTree, countedTree }, skipUsesIsNullable: true); var type = compilation.Assembly.GlobalNamespace.GetTypeMembers().First(); Assert.Equal(1, countedTree.AccessCount); // parse once to build the decl table diff --git a/src/Compilers/Core/Portable/Operations/OperationKind.cs b/src/Compilers/Core/Portable/Operations/OperationKind.cs index 0dde18f346a75600fe5c43c91ec9cf71d05869bb..efdb7fa5c0f3c61539a24df8ec4e2dcfa9dbe0d8 100644 --- a/src/Compilers/Core/Portable/Operations/OperationKind.cs +++ b/src/Compilers/Core/Portable/Operations/OperationKind.cs @@ -192,7 +192,6 @@ public enum OperationKind ConstructorBodyOperation = 0x59, /// Indicates an . Discard = 0x5A, - /// Indicates an . FlowCapture = 0x5B, /// Indicates an . @@ -205,11 +204,10 @@ public enum OperationKind StaticLocalInitializationSemaphore = 0x5F, /// Indicates an . FlowAnonymousFunction = 0x60, - /// Indicates an . - SuppressNullableWarning = 0x61, - /// Indicates an . CoalesceAssignment = 0x61, + /// Indicates an . + SuppressNullableWarning = 0x62, // /// Indicates an . // https://github.com/dotnet/roslyn/issues/21281 diff --git a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt index 52e4c180cc67f29eb35f34ac14c52017cbe33d3c..ce4c37e295ef8de920a12d8a9493183b40e6cdb5 100644 --- a/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt +++ b/src/Compilers/Core/Portable/PublicAPI.Unshipped.txt @@ -29,7 +29,7 @@ Microsoft.CodeAnalysis.FlowAnalysis.IStaticLocalInitializationSemaphoreOperation Microsoft.CodeAnalysis.FlowAnalysis.IStaticLocalInitializationSemaphoreOperation.Local.get -> Microsoft.CodeAnalysis.ILocalSymbol Microsoft.CodeAnalysis.IOperation.SemanticModel.get -> Microsoft.CodeAnalysis.SemanticModel Microsoft.CodeAnalysis.OperationKind.CoalesceAssignment = 97 -> Microsoft.CodeAnalysis.OperationKind -Microsoft.CodeAnalysis.OperationKind.SuppressNullableWarning = 97 -> Microsoft.CodeAnalysis.OperationKind +Microsoft.CodeAnalysis.OperationKind.SuppressNullableWarning = 98 -> Microsoft.CodeAnalysis.OperationKind Microsoft.CodeAnalysis.Operations.CommonConversion.IsImplicit.get -> bool Microsoft.CodeAnalysis.Operations.ICoalesceAssignmentOperation Microsoft.CodeAnalysis.Operations.ISuppressNullableWarningOperation diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs index c9bbaef87aab327e99d728855ea10b20c88d2c51..5431ebefe71c39317e83e1dadab5368c01382bd5 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/GenerateType/GenerateTypeTests.cs @@ -1536,7 +1536,7 @@ internal class T { public T(out DateTime d) { - d = default; + d = default(DateTime); } }", index: 1); @@ -1684,7 +1684,7 @@ private class T { public T(out X d) { - d = default; + d = default(X); } } }", diff --git a/src/EditorFeatures/CSharpTest/Diagnostics/UpgradeProject/UpgradeProjectTests.cs b/src/EditorFeatures/CSharpTest/Diagnostics/UpgradeProject/UpgradeProjectTests.cs index a6be2a045abdbc783a6bfe0bfd3ea57c81594766..c051b92edbede90d8978c46810cf605b727a3b49 100644 --- a/src/EditorFeatures/CSharpTest/Diagnostics/UpgradeProject/UpgradeProjectTests.cs +++ b/src/EditorFeatures/CSharpTest/Diagnostics/UpgradeProject/UpgradeProjectTests.cs @@ -550,7 +550,8 @@ void A() ", new[] { - string.Format(CSharpFeaturesResources.Upgrade_this_project_to_csharp_language_version_0, "7.0") + string.Format(CSharpFeaturesResources.Upgrade_this_project_to_csharp_language_version_0, "7.0"), + string.Format(CSharpFeaturesResources.Upgrade_all_csharp_projects_to_language_version_0, "7.0") }); } @@ -584,13 +585,16 @@ public async Task OnlyOfferFixAllProjectsToDefaultWhenApplicable() string defaultEffectiveVersion = LanguageVersion.Default.MapSpecifiedToEffectiveVersion().ToDisplayString(); await TestExactActionSetOfferedAsync( -@" +$@" class C -{ - object F = [|null!|]; -} +{{ + void A() + {{ +#error version:[|{defaultEffectiveVersion}|] + }} +}} diff --git a/src/EditorFeatures/CSharpTest/GenerateFromMembers/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersTests.cs b/src/EditorFeatures/CSharpTest/GenerateFromMembers/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersTests.cs index efb5bde48c0c3f8be5dfc3ac393d915f6cb33d8d..b77e0e9d6811198cfcd95bf9e8515a374a213c6b 100644 --- a/src/EditorFeatures/CSharpTest/GenerateFromMembers/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersTests.cs +++ b/src/EditorFeatures/CSharpTest/GenerateFromMembers/AddConstructorParametersFromMembers/AddConstructorParametersFromMembersTests.cs @@ -326,7 +326,7 @@ public Program((int, string) i) (int, string) i; (string, int) s; - public Program((int, string) i, (string, int) s = default) + public Program((int, string) i, (string, int) s = default((string, int))) { this.i = i; this.s = s; @@ -382,7 +382,7 @@ public Program((int a, string b) i) (int a, string b) i; (string c, int d) s; - public Program((int a, string b) i, (string c, int d) s = default) + public Program((int a, string b) i, (string c, int d) s = default((string c, int d))) { this.i = i; this.s = s; diff --git a/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs b/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs index 310aa150ba91894e6c90d020c7b3b395ec480590..6ee46ec7d505adfde19ea1fd653c6890e06298c0 100644 --- a/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs +++ b/src/EditorFeatures/CSharpTest/GenerateVariable/GenerateVariableTests.cs @@ -3991,7 +3991,7 @@ void bar(sfoo x) { void goo() { - sfoo xyz = default; + sfoo xyz = default(sfoo); bar(xyz); } diff --git a/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs b/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs index c11908a4228d5fc969b10890b35d861bfaae84d2..95deae176e1a766ceaddae28ddaee6bbc881922e 100644 --- a/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs +++ b/src/EditorFeatures/CSharpTest/ImplementAbstractClass/ImplementAbstractClassTests.cs @@ -459,7 +459,7 @@ abstract class d class c : d { - public override void goo(b x = default) + public override void goo(b x = default(b)) { throw new System.NotImplementedException(); } @@ -1564,7 +1564,7 @@ abstract class B } sealed class D : B { - public override void M1(int i = 0, string s = null, int? j = null, V v = default) + public override void M1(int i = 0, string s = null, int? j = null, V v = default(V)) { throw new System.NotImplementedException(); } diff --git a/src/EditorFeatures/Test2/IntelliSense/CSharpCompletionCommandHandlerTests.vb b/src/EditorFeatures/Test2/IntelliSense/CSharpCompletionCommandHandlerTests.vb index e7c6621afafcbf0f4ae8b109dbcf048aa086bcce..d3b4babea6bff060a23f11cf7862bc94724aee4a 100644 --- a/src/EditorFeatures/Test2/IntelliSense/CSharpCompletionCommandHandlerTests.vb +++ b/src/EditorFeatures/Test2/IntelliSense/CSharpCompletionCommandHandlerTests.vb @@ -1949,7 +1949,7 @@ class D : C state.SendTypeChars(" Goo") state.SendTab() Await state.AssertNoCompletionSession() - Assert.Contains("public override void Goo(S x = default)", state.SubjectBuffer.CurrentSnapshot.GetText(), StringComparison.Ordinal) + Assert.Contains("public override void Goo(S x = default(S))", state.SubjectBuffer.CurrentSnapshot.GetText(), StringComparison.Ordinal) End Using End Function diff --git a/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeClassTests.vb b/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeClassTests.vb index e8e8313908eb38e07217c0661e5f6a9152fa0030..3e78f18d34cde06d2fa16dbed5f2f2116d55e9a5 100644 --- a/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeClassTests.vb +++ b/src/VisualStudio/Core/Test/CodeModel/CSharp/CodeClassTests.vb @@ -2160,7 +2160,7 @@ class C { string Name { - get => default; + get => default(string); set { } @@ -2188,7 +2188,7 @@ class C { get { - return default; + return default(string); } set @@ -2220,7 +2220,7 @@ class C$$ class C { - string Name => default; + string Name => default(string); } @@ -2244,7 +2244,7 @@ class C { get { - return default; + return default(string); } } } diff --git a/src/Workspaces/MSBuildTest/MSBuildWorkspaceTests.cs b/src/Workspaces/MSBuildTest/MSBuildWorkspaceTests.cs index 946ff3aef5cd150853746cc0b3fd049654dc3041..9bc1ce312e6c2b2d311cbf4005413d3c3e54cdc7 100644 --- a/src/Workspaces/MSBuildTest/MSBuildWorkspaceTests.cs +++ b/src/Workspaces/MSBuildTest/MSBuildWorkspaceTests.cs @@ -1765,7 +1765,7 @@ public async Task TestParseOptions_CSharp_Compatibility_None() public async Task TestParseOptions_CSharp_LanguageVersion_Default() { CreateCSharpFiles(); - await AssertCSParseOptionsAsync(CS.LanguageVersion.CSharp8, options => options.LanguageVersion); + await AssertCSParseOptionsAsync(CS.LanguageVersion.CSharp7, options => options.LanguageVersion); } [ConditionalFact(typeof(VisualStudioMSBuildInstalled)), Trait(Traits.Feature, Traits.Features.MSBuildWorkspace)]