From af25f4714dbff39f3a0910e0b5ea21e278eb58d4 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Sun, 23 Aug 2020 13:58:46 +0200 Subject: [PATCH 01/39] Raise the default warning level in tests --- .../Test/Utilities/CSharp/TestOptions.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs index 71878e0157cf4..73a3341d75582 100644 --- a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs +++ b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs @@ -47,34 +47,34 @@ public static class TestOptions public static readonly CSharpParseOptions RegularWithoutPatternCombinators = Regular8; public static readonly CSharpParseOptions RegularWithPatternCombinators = RegularPreview; - public static readonly CSharpCompilationOptions ReleaseDll = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release); - public static readonly CSharpCompilationOptions ReleaseExe = new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Release); + public static readonly CSharpCompilationOptions ReleaseDll = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5); + public static readonly CSharpCompilationOptions ReleaseExe = new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5); - public static readonly CSharpCompilationOptions ReleaseDebugDll = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release). + public static readonly CSharpCompilationOptions ReleaseDebugDll = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5). WithDebugPlusMode(true); - public static readonly CSharpCompilationOptions ReleaseDebugExe = new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Release). + public static readonly CSharpCompilationOptions ReleaseDebugExe = new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5). WithDebugPlusMode(true); - public static readonly CSharpCompilationOptions DebugDll = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Debug); - public static readonly CSharpCompilationOptions DebugExe = new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Debug); + public static readonly CSharpCompilationOptions DebugDll = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Debug).WithWarningLevel(5); + public static readonly CSharpCompilationOptions DebugExe = new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Debug).WithWarningLevel(5); - public static readonly CSharpCompilationOptions ReleaseWinMD = new CSharpCompilationOptions(OutputKind.WindowsRuntimeMetadata, optimizationLevel: OptimizationLevel.Release); - public static readonly CSharpCompilationOptions DebugWinMD = new CSharpCompilationOptions(OutputKind.WindowsRuntimeMetadata, optimizationLevel: OptimizationLevel.Debug); + public static readonly CSharpCompilationOptions ReleaseWinMD = new CSharpCompilationOptions(OutputKind.WindowsRuntimeMetadata, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5); + public static readonly CSharpCompilationOptions DebugWinMD = new CSharpCompilationOptions(OutputKind.WindowsRuntimeMetadata, optimizationLevel: OptimizationLevel.Debug).WithWarningLevel(5); - public static readonly CSharpCompilationOptions ReleaseModule = new CSharpCompilationOptions(OutputKind.NetModule, optimizationLevel: OptimizationLevel.Release); - public static readonly CSharpCompilationOptions DebugModule = new CSharpCompilationOptions(OutputKind.NetModule, optimizationLevel: OptimizationLevel.Debug); + public static readonly CSharpCompilationOptions ReleaseModule = new CSharpCompilationOptions(OutputKind.NetModule, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5); + public static readonly CSharpCompilationOptions DebugModule = new CSharpCompilationOptions(OutputKind.NetModule, optimizationLevel: OptimizationLevel.Debug).WithWarningLevel(5); - public static readonly CSharpCompilationOptions UnsafeReleaseDll = ReleaseDll.WithAllowUnsafe(true); - public static readonly CSharpCompilationOptions UnsafeReleaseExe = ReleaseExe.WithAllowUnsafe(true); + public static readonly CSharpCompilationOptions UnsafeReleaseDll = ReleaseDll.WithAllowUnsafe(true).WithWarningLevel(5); + public static readonly CSharpCompilationOptions UnsafeReleaseExe = ReleaseExe.WithAllowUnsafe(true).WithWarningLevel(5); - public static readonly CSharpCompilationOptions UnsafeDebugDll = DebugDll.WithAllowUnsafe(true); - public static readonly CSharpCompilationOptions UnsafeDebugExe = DebugExe.WithAllowUnsafe(true); + public static readonly CSharpCompilationOptions UnsafeDebugDll = DebugDll.WithAllowUnsafe(true).WithWarningLevel(5); + public static readonly CSharpCompilationOptions UnsafeDebugExe = DebugExe.WithAllowUnsafe(true).WithWarningLevel(5); - public static readonly CSharpCompilationOptions SigningReleaseDll = ReleaseDll.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider); - public static readonly CSharpCompilationOptions SigningReleaseExe = ReleaseExe.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider); - public static readonly CSharpCompilationOptions SigningReleaseModule = ReleaseModule.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider); - public static readonly CSharpCompilationOptions SigningDebugDll = DebugDll.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider); + public static readonly CSharpCompilationOptions SigningReleaseDll = ReleaseDll.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider).WithWarningLevel(5); + public static readonly CSharpCompilationOptions SigningReleaseExe = ReleaseExe.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider).WithWarningLevel(5); + public static readonly CSharpCompilationOptions SigningReleaseModule = ReleaseModule.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider).WithWarningLevel(5); + public static readonly CSharpCompilationOptions SigningDebugDll = DebugDll.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider).WithWarningLevel(5); public static readonly EmitOptions NativePdbEmit = EmitOptions.Default.WithDebugInformationFormat(DebugInformationFormat.Pdb); From 7faffae9728fb2bafa8159b112bcb663dfe008e0 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Sun, 23 Aug 2020 14:04:13 +0200 Subject: [PATCH 02/39] Update CompilationWithAnalyzersTests.cs --- .../Diagnostics/CompilationWithAnalyzersTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs index 9372750b4ed4a..481a3e931dc81 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs @@ -35,7 +35,7 @@ public void GetEffectiveDiagnostics_Errors() [Fact] public void GetEffectiveDiagnostics() { - var c = CSharpCompilation.Create("c", options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary). + var c = CSharpCompilation.Create("c", options: TestOptions.ReleaseDll. WithSpecificDiagnosticOptions( new[] { KeyValuePairUtil.Create($"CS{(int)ErrorCode.WRN_AlwaysNull:D4}", ReportDiagnostic.Suppress) })); @@ -54,7 +54,7 @@ public void GetEffectiveDiagnostics() [Fact] public void GetAnalyzerTelemetry() { - var compilation = CSharpCompilation.Create("c", options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + var compilation = CSharpCompilation.Create("c", options: TestOptions.ReleaseDll); DiagnosticAnalyzer analyzer = new AnalyzerWithDisabledRules(); var analyzers = ImmutableArray.Create(analyzer); var analyzerOptions = new AnalyzerOptions(ImmutableArray.Empty); @@ -73,7 +73,7 @@ public void TestIsDiagnosticAnalyzerSuppressedWithExceptionInSupportedDiagnostic { // Verify IsDiagnosticAnalyzerSuppressed does not throw an exception when 'onAnalyzerException' is null. var analyzer = new AnalyzerThatThrowsInSupportedDiagnostics(); - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); + var options = TestOptions.ReleaseDll; _ = CompilationWithAnalyzers.IsDiagnosticAnalyzerSuppressed(analyzer, options, onAnalyzerException: null); } } From d77232ddc2a26612c6d8b4f484851ac844d0db40 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Sun, 23 Aug 2020 14:08:09 +0200 Subject: [PATCH 03/39] Update MetadataMemberTests.cs --- .../Symbols/Metadata/MetadataMemberTests.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs index 8033d11624d56..4332c41aa4861 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs @@ -682,7 +682,7 @@ public void TestMetadataImportOptions_01() Diagnostic(ErrorCode.ERR_BadCompilationOptionValue).WithArguments("MetadataImportOptions", "255").WithLocation(1, 1) }; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); + var options = TestOptions.ReleaseDll; Assert.Equal(MetadataImportOptions.Public, options.MetadataImportOptions); options.VerifyErrors(); @@ -724,7 +724,7 @@ public class C "; var compilation0 = CreateCompilation(source); - options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); + options = TestOptions.ReleaseDll; var compilation = CreateCompilation("", options: options, references: new[] { compilation0.EmitToImageReference() }); var c = compilation.GetTypeByMetadataName("C"); Assert.NotEmpty(c.GetMembers("P1")); @@ -764,16 +764,16 @@ public void TestMetadataImportOptions_02() Diagnostic(ErrorCode.ERR_BadCompilationOptionValue).WithArguments("MetadataImportOptions", "255").WithLocation(1, 1) }; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: MetadataImportOptions.Internal); + var options = TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.Internal); Assert.Equal(MetadataImportOptions.Internal, options.MetadataImportOptions); options.VerifyErrors(); - options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: MetadataImportOptions.All); + options = TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All); Assert.Equal(MetadataImportOptions.All, options.MetadataImportOptions); options.VerifyErrors(); - options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: MetadataImportOptions.Public); + options = TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.Public); Assert.Equal(MetadataImportOptions.Public, options.MetadataImportOptions); options.VerifyErrors(); - options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: (MetadataImportOptions)byte.MaxValue); + options = TestOptions.ReleaseDll.WithMetadataImportOptions((MetadataImportOptions)byte.MaxValue); Assert.Equal((MetadataImportOptions)byte.MaxValue, options.MetadataImportOptions); options.VerifyErrors(expectedDiagnostics); @@ -787,21 +787,21 @@ public class C "; var compilation0 = CreateCompilation(source); - var compilation = CreateCompilation("", options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: MetadataImportOptions.Internal), references: new[] { compilation0.EmitToImageReference() }); + var compilation = CreateCompilation("", options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.Internal), references: new[] { compilation0.EmitToImageReference() }); var c = compilation.GetTypeByMetadataName("C"); Assert.NotEmpty(c.GetMembers("P1")); Assert.NotEmpty(c.GetMembers("P2")); Assert.Empty(c.GetMembers("P3")); CompileAndVerify(compilation); - compilation = compilation.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: MetadataImportOptions.All)); + compilation = compilation.WithOptions(TestOptions.ReleaseDll.WithMetadataImportOptions(metadataImportOptions: MetadataImportOptions.All)); c = compilation.GetTypeByMetadataName("C"); Assert.NotEmpty(c.GetMembers("P1")); Assert.NotEmpty(c.GetMembers("P2")); Assert.NotEmpty(c.GetMembers("P3")); CompileAndVerify(compilation); - compilation = compilation.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: (MetadataImportOptions)byte.MaxValue)); + compilation = compilation.WithOptions(TestOptions.ReleaseDll.WithMetadataImportOptions((MetadataImportOptions)byte.MaxValue)); c = compilation.GetTypeByMetadataName("C"); Assert.NotEmpty(c.GetMembers("P1")); Assert.NotEmpty(c.GetMembers("P2")); From dd454c4d78bcce553c57ef45bf4a0f016d341027 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Sun, 23 Aug 2020 14:09:10 +0200 Subject: [PATCH 04/39] Update CSharpDeterministicBuildCompilationTests.cs --- .../Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs index 2d1a3f894938a..eae3305358b7d 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs @@ -235,7 +235,7 @@ private static IEnumerable GetCompilationOptions() delaySign: null, platform: Platform.AnyCpu, generalDiagnosticOption: ReportDiagnostic.Default, - warningLevel: 4, + warningLevel: 5, specificDiagnosticOptions: null, concurrentBuild: true, deterministic: true, From a80d03e1ba10013177025983eb2b4a492589db07 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Sun, 23 Aug 2020 14:11:04 +0200 Subject: [PATCH 05/39] Update AssemblyAndNamespaceTests.cs --- .../Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs index 5ae2d14a27c66..393ad2c9f703b 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs @@ -112,11 +112,11 @@ struct S {} } } "; - var comp1 = CSharpCompilation.Create(assemblyName: "Test", options: new CSharpCompilationOptions(OutputKind.ConsoleApplication), + var comp1 = CSharpCompilation.Create(assemblyName: "Test", options: TestOptions.ReleaseExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text) }, references: new MetadataReference[] { }); var compRef = new CSharpCompilationReference(comp1); - var comp = CSharpCompilation.Create(assemblyName: "Test1", options: new CSharpCompilationOptions(OutputKind.ConsoleApplication), + var comp = CSharpCompilation.Create(assemblyName: "Test1", options: TestOptions.ReleaseExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text1), SyntaxFactory.ParseSyntaxTree(text2) }, references: new MetadataReference[] { compRef }); @@ -159,7 +159,7 @@ class C : NN.B { } var comp1 = CreateCompilation(text); var compRef = new CSharpCompilationReference(comp1); - var comp = CSharpCompilation.Create(assemblyName: "Test1", options: new CSharpCompilationOptions(OutputKind.ConsoleApplication), + var comp = CSharpCompilation.Create(assemblyName: "Test1", options: TestOptions.ReleaseExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text1), SyntaxFactory.ParseSyntaxTree(text2) }, references: new MetadataReference[] { compRef }); @@ -246,13 +246,13 @@ struct SGoo {} } "; - var comp1 = CSharpCompilation.Create(assemblyName: "Test1", options: new CSharpCompilationOptions(OutputKind.ConsoleApplication), syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text1) }, references: new MetadataReference[] { }); - var comp2 = CSharpCompilation.Create(assemblyName: "Test2", options: new CSharpCompilationOptions(OutputKind.ConsoleApplication), syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text2) }, references: new MetadataReference[] { }); + var comp1 = CSharpCompilation.Create(assemblyName: "Test1", options: TestOptions.ReleaseExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text1) }, references: new MetadataReference[] { }); + var comp2 = CSharpCompilation.Create(assemblyName: "Test2", options: TestOptions.ReleaseExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text2) }, references: new MetadataReference[] { }); var compRef1 = new CSharpCompilationReference(comp1); var compRef2 = new CSharpCompilationReference(comp2); - var comp = CSharpCompilation.Create(assemblyName: "Test3", options: new CSharpCompilationOptions(OutputKind.ConsoleApplication), + var comp = CSharpCompilation.Create(assemblyName: "Test3", options: TestOptions.ReleaseExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text3) }, references: new MetadataReference[] { compRef1, compRef2 }); From ceed1f86bbe90827ce481367922061b2d58271ba Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Sun, 23 Aug 2020 16:16:24 +0200 Subject: [PATCH 06/39] Update MetadataMemberTests.cs --- .../CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs index 4332c41aa4861..dd7cad49a7ba8 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs @@ -794,7 +794,7 @@ public class C Assert.Empty(c.GetMembers("P3")); CompileAndVerify(compilation); - compilation = compilation.WithOptions(TestOptions.ReleaseDll.WithMetadataImportOptions(metadataImportOptions: MetadataImportOptions.All)); + compilation = compilation.WithOptions(TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All)); c = compilation.GetTypeByMetadataName("C"); Assert.NotEmpty(c.GetMembers("P1")); Assert.NotEmpty(c.GetMembers("P2")); From afc64be490dc83ecf3787495fe9d1d04b2dc4dda Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Sun, 23 Aug 2020 16:17:09 +0200 Subject: [PATCH 07/39] Update CompilationWithAnalyzersTests.cs --- .../Diagnostics/CompilationWithAnalyzersTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs index 481a3e931dc81..f7ba715e937fa 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs @@ -8,6 +8,7 @@ using System.Linq; using System.Threading; using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Diagnostics; using Roslyn.Test.Utilities; using Roslyn.Utilities; From f0950fc44ab790d5dd5f90a0b54dd3ef312f0a5e Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 24 Aug 2020 12:14:44 +0000 Subject: [PATCH 08/39] More updates --- .../Test/CommandLine/CommandLineTests.cs | 3 +- .../Attributes/AttributeTests_IsUnmanaged.cs | 6 +- .../Attributes/AttributeTests_Synthesized.cs | 85 ++++++++----------- .../InternalsVisibleToAndStrongNameTests.cs | 8 +- .../CodeGenDisplayClassOptimisationTests.cs | 4 +- .../Test/Emit/CodeGen/CodeGenTupleTest.cs | 2 +- .../Test/Emit/Emit/CompilationEmitTests.cs | 16 ++-- .../Test/Emit/Emit/DeterministicTests.cs | 2 +- .../CSharp/Test/Emit/Emit/EndToEndTests.cs | 2 +- .../Test/Semantic/Semantics/ArglistTests.cs | 4 +- .../Semantic/Semantics/InterpolationTests.cs | 4 +- .../AnalyzerFileReferenceAppDomainTests.cs | 7 +- .../Core/CodeAnalysisTest/CorLibTypesTests.cs | 4 +- .../CompilationWithAnalyzersTests.cs | 14 ++- .../ShadowCopyAnalyzerAssemblyLoaderTests.cs | 16 ++-- .../Test/Utilities/CSharp/TestOptions.cs | 43 +++++----- 16 files changed, 108 insertions(+), 112 deletions(-) diff --git a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs index a3895e32b279e..fbf90fdc6294d 100644 --- a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs +++ b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs @@ -2481,7 +2481,8 @@ public void Optimize() { var parsedArgs = DefaultParse(new[] { "a.cs" }, WorkingDirectory); parsedArgs.Errors.Verify(); - Assert.Equal(new CSharpCompilationOptions(OutputKind.ConsoleApplication).OptimizationLevel, parsedArgs.CompilationOptions.OptimizationLevel); + // TODO: I think the test is more clear with the old approach (explicitly creating CSharpCompilationOptions). What do you think? + Assert.Equal(TestOptions.DebugExe.OptimizationLevel, parsedArgs.CompilationOptions.OptimizationLevel); parsedArgs = DefaultParse(new[] { "/optimize-", "a.cs" }, WorkingDirectory); parsedArgs.Errors.Verify(); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs index 7355ea43e903c..f840ecc20feb4 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_IsUnmanaged.cs @@ -767,7 +767,7 @@ class Test where T : unmanaged { }"; - CreateCompilation(text, options: new CSharpCompilationOptions(outputKind)).VerifyDiagnostics( + CreateCompilation(text, options: TestOptions.DebugDll.WithOutputKind(outputKind)).VerifyDiagnostics( // (9,12): error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.IsUnmanagedAttribute..ctor' // class Test where T : unmanaged Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "T").WithArguments("System.Runtime.CompilerServices.IsUnmanagedAttribute", ".ctor").WithLocation(9, 12)); @@ -790,7 +790,7 @@ class Test where T : unmanaged { }"; - CreateCompilation(text, options: new CSharpCompilationOptions(outputKind)).VerifyDiagnostics( + CreateCompilation(text, options: TestOptions.DebugDll.WithOutputKind(outputKind)).VerifyDiagnostics( // (9,12): error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.IsUnmanagedAttribute..ctor' // class Test where T : unmanaged Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "T").WithArguments("System.Runtime.CompilerServices.IsUnmanagedAttribute", ".ctor").WithLocation(9, 12)); @@ -810,7 +810,7 @@ class Test where T : unmanaged { }"; - CreateCompilation(text, options: new CSharpCompilationOptions(outputKind)).VerifyDiagnostics( + CreateCompilation(text, options: TestOptions.DebugDll.WithOutputKind(outputKind)).VerifyDiagnostics( // (6,12): error CS0656: Missing compiler required member 'System.Runtime.CompilerServices.IsUnmanagedAttribute..ctor' // class Test where T : unmanaged Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "T").WithArguments("System.Runtime.CompilerServices.IsUnmanagedAttribute", ".ctor").WithLocation(6, 12)); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs index 4fda76d3267df..b73851939fb79 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs @@ -166,8 +166,7 @@ class Test public event Func MyEvent; } "; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(source, options: options, symbolValidator: module => @@ -216,8 +215,7 @@ abstract class C public event Func E; } "; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(source, options: options, symbolValidator: module => @@ -256,8 +254,7 @@ void Goo() } } "; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilation(source, options: options), symbolValidator: m => @@ -285,8 +282,7 @@ void Goo() } } "; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilation(source, options: options), symbolValidator: m => @@ -424,8 +420,7 @@ public IEnumerable Iterator() } } "; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilation(source, options: options), symbolValidator: module => @@ -480,8 +475,7 @@ public async Task Goo() } } "; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -539,8 +533,7 @@ public override async Task GetIntAsync() } } "; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -578,8 +571,7 @@ public override async Task GetIntAsync(int x) } } "; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -622,8 +614,7 @@ public override async Task GetAsync<[Attr] T>([Attr] T t) } } "; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -673,7 +664,7 @@ public static void Main() { } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -708,7 +699,7 @@ public static void Main() { } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -743,7 +734,7 @@ public static void Main() { } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -778,7 +769,7 @@ public static void Main() { } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -814,7 +805,7 @@ public static void Main() { } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { VerifyDebuggableAttribute(module.GetAttributes().Single(), optimizationLevel, isSynthesized: false); @@ -852,7 +843,7 @@ public static void Main() { } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -887,7 +878,7 @@ public static void Main() { } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { VerifyCompilationRelaxationsAttribute(module.GetAttributes().Single(), isSynthesized: false); @@ -924,7 +915,7 @@ public static void Main() { } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { VerifyDebuggableAttribute(module.GetAttributes().Single(), options.OptimizationLevel, isSynthesized: false); @@ -950,7 +941,7 @@ public static void Main() [MemberData(nameof(FullMatrixTheoryData))] public void MissingWellKnownAttributesNoDiagnosticsAndNoSynthesizedAttributes(OutputKind outputKind, OptimizationLevel optimizationLevel) { - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); var compilation = CreateEmptyCompilation("", options: options); if (outputKind.IsApplication()) @@ -988,7 +979,7 @@ public static void Main() } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); var compilation = CreateCompilation(code, options: options); CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => @@ -1037,7 +1028,7 @@ public static void Main() } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); var compilation = CreateCompilation(code, options: options); CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => @@ -1084,7 +1075,7 @@ public static void Main() } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); var compilation = CreateCompilation(code, options: options); CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => @@ -1128,7 +1119,7 @@ public static void Main() } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); var compilation = CreateCompilation(code, options: options); CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => @@ -1171,7 +1162,7 @@ public static void Main() { } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); var compilation = CreateCompilation(source, options: options); if (outputKind.IsNetModule()) @@ -1202,7 +1193,7 @@ public void AppliedCompilationRelaxationsOnModuleSupressesAssemblyAttributes(Out using System.Runtime.CompilerServices; [assembly: CompilationRelaxationsAttribute(0)] -", options: new CSharpCompilationOptions(OutputKind.NetModule, optimizationLevel: optimizationLevel)); +", options: TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel)); var reference = ModuleMetadata.CreateFromImage(referenceComp.EmitToArray()).GetReference(); @@ -1215,7 +1206,7 @@ public static void Main() } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); CompileAndVerify(source, references: new[] { reference }, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -1243,7 +1234,7 @@ public void AppliedRuntimeCompatibilityOnModuleSupressesAssemblyAttributes(Outpu using System.Runtime.CompilerServices; [assembly: RuntimeCompatibilityAttribute()] -", options: new CSharpCompilationOptions(OutputKind.NetModule, optimizationLevel: optimizationLevel)); +", options: TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel)); var reference = ModuleMetadata.CreateFromImage(referenceComp.EmitToArray()).GetReference(); @@ -1256,7 +1247,7 @@ public static void Main() } }"; - var options = new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel); + var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); CompileAndVerify(source, references: new[] { reference }, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -1291,10 +1282,7 @@ public static void Main() } }"; - var compilation = CreateCompilationWithMscorlib40(source, options: new CSharpCompilationOptions( - outputKind: outputKind, - optimizationLevel: OptimizationLevel.Release, - allowUnsafe: true)); + var compilation = CreateCompilationWithMscorlib40(source, options: TestOptions.UnsafeReleaseDll.WithOutputKind(outputKind)); //Skipped because PeVerify fails to run with "The module was expected to contain an assembly manifest." CompileAndVerify(compilation, verify: Verification.Skipped, symbolValidator: module => @@ -1357,7 +1345,7 @@ public static async void F() } }"; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) + var options = TestOptions.DebugDll .WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); @@ -1401,7 +1389,7 @@ public static void F() } }"; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) + var options = TestOptions.DebugDll .WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); @@ -1444,7 +1432,7 @@ public class Test } }"; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) + var options = TestOptions.DebugDll .WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); @@ -1487,7 +1475,7 @@ public static async void F() } }"; - var referenceOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) + var referenceOptions = TestOptions.DebugDll .WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); var reference = CreateCompilationWithMscorlib45(source, options: referenceOptions).EmitToImageReference(options: new EmitOptions(metadataOnly: true)); @@ -1527,8 +1515,7 @@ public static IEnumerable F() } }"; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -1558,8 +1545,7 @@ public class Test } }"; - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -1589,8 +1575,7 @@ public class Test } }"; - var referenceOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) - .WithOptimizationLevel(optimizationLevel) + var referenceOptions = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); var reference = CreateCompilationWithMscorlib45(source, options: referenceOptions).EmitToImageReference(options: new EmitOptions(metadataOnly: true)); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index a2fcaa288ec6a..39863116dacc0 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -2623,7 +2623,7 @@ public void Bug1095618(CSharpParseOptions parseOptions) [MemberData(nameof(AllProviderParseOptions))] public void ConsistentErrorMessageWhenProvidingNullKeyFile(CSharpParseOptions parseOptions) { - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, cryptoKeyFile: null); + var options = TestOptions.DebugDll; var compilation = CreateCompilation(string.Empty, options: options, parseOptions: parseOptions).VerifyDiagnostics(); VerifySignedBitSetAfterEmit(compilation, expectedToBeSigned: false); @@ -2634,7 +2634,7 @@ public void ConsistentErrorMessageWhenProvidingNullKeyFile(CSharpParseOptions pa [MemberData(nameof(AllProviderParseOptions))] public void ConsistentErrorMessageWhenProvidingEmptyKeyFile(CSharpParseOptions parseOptions) { - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, cryptoKeyFile: string.Empty); + var options = TestOptions.DebugDll.WithCryptoKeyFile(string.Empty); var compilation = CreateCompilation(string.Empty, options: options, parseOptions: parseOptions).VerifyDiagnostics(); VerifySignedBitSetAfterEmit(compilation, expectedToBeSigned: false); @@ -2645,7 +2645,7 @@ public void ConsistentErrorMessageWhenProvidingEmptyKeyFile(CSharpParseOptions p [MemberData(nameof(AllProviderParseOptions))] public void ConsistentErrorMessageWhenProvidingNullKeyFile_PublicSign(CSharpParseOptions parseOptions) { - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, cryptoKeyFile: null, publicSign: true); + var options = TestOptions.DebugDll.WithPublicSign(true); CreateCompilation(string.Empty, options: options, parseOptions: parseOptions).VerifyDiagnostics( // error CS8102: Public signing was specified and requires a public key, but no public key was specified. Diagnostic(ErrorCode.ERR_PublicSignButNoKey).WithLocation(1, 1)); @@ -2656,7 +2656,7 @@ public void ConsistentErrorMessageWhenProvidingNullKeyFile_PublicSign(CSharpPars [MemberData(nameof(AllProviderParseOptions))] public void ConsistentErrorMessageWhenProvidingEmptyKeyFile_PublicSign(CSharpParseOptions parseOptions) { - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, cryptoKeyFile: string.Empty, publicSign: true); + var options = TestOptions.DebugDll.WithCryptoKeyFile(string.Empty).WithPublicSign(true); CreateCompilation(string.Empty, options: options, parseOptions: parseOptions).VerifyDiagnostics( // error CS8102: Public signing was specified and requires a public key, but no public key was specified. Diagnostic(ErrorCode.ERR_PublicSignButNoKey).WithLocation(1, 1)); diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDisplayClassOptimisationTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDisplayClassOptimisationTests.cs index 3f35ada855609..0fe5b6d11c5f3 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDisplayClassOptimisationTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenDisplayClassOptimisationTests.cs @@ -40,7 +40,7 @@ public static void Main() } } }"; - var compilation = CompileAndVerify(source, expectedOutput: @"3", options: new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Release)); + var compilation = CompileAndVerify(source, expectedOutput: @"3", options: TestOptions.ReleaseExe); VerifyTypeIL(compilation, "Program", @" .class public auto ansi abstract sealed beforefieldinit Program @@ -124,7 +124,7 @@ public static void Main() } } }"; - var compilation = CompileAndVerify(source, expectedOutput: @"3", options: new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Debug)); + var compilation = CompileAndVerify(source, expectedOutput: @"3", options: TestOptions.DebugExe); VerifyTypeIL(compilation, "Program", @" .class public auto ansi abstract sealed beforefieldinit Program diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs index fe7d28dd30112..a4d7de3d32064 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenTupleTest.cs @@ -27053,7 +27053,7 @@ public static string GetFromExternal() } } "; - var compilation = CreateCompilationWithMscorlib45(source, null, new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithAllowUnsafe(true)); + var compilation = CreateCompilationWithMscorlib45(source, null, TestOptions.UnsafeDebugExe); CompileAndVerify(compilation, expectedOutput: "MessageType x MessageType").VerifyDiagnostics(); } diff --git a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs index 372611a5983de..dc8dd79782b4e 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs @@ -3211,7 +3211,7 @@ public static void Main() } }"; var compilation = CreateCompilation(source, - options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.X86)); + options: TestOptions.DebugDll.WithPlatform(Platform.X86)); var peHeaders = new PEHeaders(compilation.EmitToStream()); @@ -3245,7 +3245,7 @@ public static void Main() } }"; var compilation = CreateCompilation(source, - options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.X64)); + options: TestOptions.DebugDll.WithPlatform(Platform.X64)); var peHeaders = new PEHeaders(compilation.EmitToStream()); @@ -3295,7 +3295,7 @@ public static void Main() } }"; var compilation = CreateCompilation(source, - options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithPlatform(Platform.Arm)); + options: TestOptions.DebugDll.WithPlatform(Platform.Arm)); var peHeaders = new PEHeaders(compilation.EmitToStream()); @@ -3426,7 +3426,7 @@ public static void Main() { } }"; - var compilation = CreateCompilation(source, options: new CSharpCompilationOptions(OutputKind.WindowsRuntimeApplication)); + var compilation = CreateCompilation(source, options: TestOptions.DebugWindowsRuntimeApp); var peHeaders = new PEHeaders(compilation.EmitToStream()); //interesting COFF bits @@ -5244,7 +5244,7 @@ public void CompileAndVerifyModuleIncludesAllModules() [WorkItem(37779, "https://github.com/dotnet/roslyn/issues/37779")] public void WarnAsErrorDoesNotEmit_GeneralDiagnosticOption() { - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, generalDiagnosticOption: ReportDiagnostic.Error); + var options = TestOptions.DebugDll.WithGeneralDiagnosticOption(ReportDiagnostic.Error); TestWarnAsErrorDoesNotEmitCore(options); } @@ -5252,7 +5252,7 @@ public void WarnAsErrorDoesNotEmit_GeneralDiagnosticOption() [WorkItem(37779, "https://github.com/dotnet/roslyn/issues/37779")] public void WarnAsErrorDoesNotEmit_SpecificDiagnosticOption() { - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithSpecificDiagnosticOptions("CS0169", ReportDiagnostic.Error); + var options = TestOptions.DebugDll.WithSpecificDiagnosticOptions("CS0169", ReportDiagnostic.Error); TestWarnAsErrorDoesNotEmitCore(options); } @@ -5289,7 +5289,7 @@ class X [WorkItem(37779, "https://github.com/dotnet/roslyn/issues/37779")] public void WarnAsErrorWithMetadataOnlyImageDoesEmit_GeneralDiagnosticOption() { - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, generalDiagnosticOption: ReportDiagnostic.Error); + var options = TestOptions.DebugDll.WithGeneralDiagnosticOption(ReportDiagnostic.Error); TestWarnAsErrorWithMetadataOnlyImageDoesEmitCore(options); } @@ -5297,7 +5297,7 @@ public void WarnAsErrorWithMetadataOnlyImageDoesEmit_GeneralDiagnosticOption() [WorkItem(37779, "https://github.com/dotnet/roslyn/issues/37779")] public void WarnAsErrorWithMetadataOnlyImageDoesEmit_SpecificDiagnosticOptions() { - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithSpecificDiagnosticOptions("CS0612", ReportDiagnostic.Error); + var options = TestOptions.DebugDll.WithSpecificDiagnosticOptions("CS0612", ReportDiagnostic.Error); TestWarnAsErrorWithMetadataOnlyImageDoesEmitCore(options); } diff --git a/src/Compilers/CSharp/Test/Emit/Emit/DeterministicTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/DeterministicTests.cs index affec9427a8bd..adafe561e697d 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/DeterministicTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/DeterministicTests.cs @@ -261,7 +261,7 @@ public void TestWriteOnlyStream() var compilation = CSharpCompilation.Create("Program", new[] { tree }, new[] { MetadataReference.CreateFromAssemblyInternal(typeof(object).Assembly) }, - new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithDeterministic(true)); + TestOptions.DebugExe.WithDeterministic(true)); var output = new WriteOnlyStream(); compilation.Emit(output); } diff --git a/src/Compilers/CSharp/Test/Emit/Emit/EndToEndTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/EndToEndTests.cs index 78aea607cb9ed..2404d245d624f 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/EndToEndTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/EndToEndTests.cs @@ -139,7 +139,7 @@ void M2() { var source = builder.ToString(); RunInThread(() => { - var options = new CSharpCompilationOptions(outputKind: OutputKind.DynamicallyLinkedLibrary, concurrentBuild: false); + var options = TestOptions.DebugDll.WithConcurrentBuild(false); var compilation = CreateCompilation(source, options: options); compilation.VerifyDiagnostics(); compilation.EmitToArray(); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs index 9b69edd7581db..79ad78efa5824 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/ArglistTests.cs @@ -1632,7 +1632,7 @@ static void Main() Console.WriteLine(a); } }", - options: new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Debug), + options: TestOptions.DebugExe, expectedOutput: "5"); } @@ -1655,7 +1655,7 @@ static void Main() Test(__arglist(a)); } }", - options: new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Debug), + options: TestOptions.DebugExe, expectedOutput: "5"); } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index e5710426b97bf..ee069549453b7 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -924,7 +924,7 @@ public static void Main() } } }"; - CreateEmptyCompilation(text, options: new CSharpCompilationOptions(OutputKind.ConsoleApplication)) + CreateEmptyCompilation(text, options: TestOptions.DebugExe) .VerifyEmitDiagnostics(new CodeAnalysis.Emit.EmitOptions(runtimeMetadataVersion: "x.y"), // (15,21): error CS0117: 'string' does not contain a definition for 'Format' // var s = $"X = { 1 } "; @@ -957,7 +957,7 @@ public static void Main() } } }"; - CreateEmptyCompilation(text, options: new CSharpCompilationOptions(OutputKind.ConsoleApplication)) + CreateEmptyCompilation(text, options: TestOptions.DebugExe) .VerifyEmitDiagnostics(new CodeAnalysis.Emit.EmitOptions(runtimeMetadataVersion: "x.y"), // (17,21): error CS0029: Cannot implicitly convert type 'bool' to 'string' // var s = $"X = { 1 } "; diff --git a/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs b/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs index 4e5ede1529564..8b983cb9288fb 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs @@ -37,6 +37,8 @@ public Exception LoadAnalyzer(string analyzerPath) public class AnalyzerFileReferenceAppDomainTests : TestBase { + private const int MaxWarningLevel = 9999; + [Fact] public void TestAnalyzerLoading_AppDomain() { @@ -97,7 +99,7 @@ public class TestAnalyzer : DiagnosticAnalyzer MetadataReference.CreateFromFile(immutable.Path), MetadataReference.CreateFromFile(analyzer.Path) }, - new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: MaxWarningLevel)); var analyzerFile = dir.CreateFile("MyAnalyzer.dll").WriteAllBytes(analyzerCompilation.EmitToArray()); @@ -118,7 +120,8 @@ public class TestAnalyzer : DiagnosticAnalyzer private static Assembly OnResolve(object sender, ResolveEventArgs e) { Console.WriteLine($"Resolve in {AppDomain.CurrentDomain.Id} for {e.Name}"); - return null; + return null; // Question: How nullable is enabled, and return type is `Assembly` not `Assembly?` without any CI build errors? + // I see there are no references to this method, should it be safely deleted? } } } diff --git a/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs b/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs index 04d7b56670059..a58a1bda63cd1 100644 --- a/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs @@ -10,6 +10,8 @@ namespace Microsoft.CodeAnalysis.UnitTests { public class CorLibTypesAndConstantTests : TestBase { + private const int MaxWarningLevel = 9999; + [Fact] public void IntegrityTest() { @@ -62,7 +64,7 @@ public void SpecialTypeIsValueType() { var comp = CSharp.CSharpCompilation.Create( "c", - options: new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary), + options: new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: MaxWarningLevel), references: new[] { TestMetadata.NetCoreApp31.SystemRuntime }); for (var specialType = SpecialType.None + 1; specialType <= SpecialType.Count; specialType++) diff --git a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs index f7ba715e937fa..9b2cfe32335d8 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs @@ -3,15 +3,11 @@ // See the LICENSE file in the project root for more information. using System; -using System.Collections.Generic; using System.Collections.Immutable; -using System.Linq; using System.Threading; using Microsoft.CodeAnalysis.CSharp; -using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Diagnostics; using Roslyn.Test.Utilities; -using Roslyn.Utilities; using Xunit; using static Microsoft.CodeAnalysis.CommonDiagnosticAnalyzers; using KeyValuePairUtil = Roslyn.Utilities.KeyValuePairUtil; @@ -22,6 +18,9 @@ namespace Microsoft.CodeAnalysis.UnitTests.Diagnostics public class CompilationWithAnalyzersTests : TestBase { + private const int MaxWarningLevel = 9999; + private static readonly CSharpCompilationOptions s_dllWithMaxWarningLevel = new(OutputKind.DynamicallyLinkedLibrary, warningLevel: MaxWarningLevel); + [Fact] public void GetEffectiveDiagnostics_Errors() { @@ -36,7 +35,7 @@ public void GetEffectiveDiagnostics_Errors() [Fact] public void GetEffectiveDiagnostics() { - var c = CSharpCompilation.Create("c", options: TestOptions.ReleaseDll. + var c = CSharpCompilation.Create("c", options: s_dllWithMaxWarningLevel. WithSpecificDiagnosticOptions( new[] { KeyValuePairUtil.Create($"CS{(int)ErrorCode.WRN_AlwaysNull:D4}", ReportDiagnostic.Suppress) })); @@ -55,7 +54,7 @@ public void GetEffectiveDiagnostics() [Fact] public void GetAnalyzerTelemetry() { - var compilation = CSharpCompilation.Create("c", options: TestOptions.ReleaseDll); + var compilation = CSharpCompilation.Create("c", options: s_dllWithMaxWarningLevel); DiagnosticAnalyzer analyzer = new AnalyzerWithDisabledRules(); var analyzers = ImmutableArray.Create(analyzer); var analyzerOptions = new AnalyzerOptions(ImmutableArray.Empty); @@ -74,8 +73,7 @@ public void TestIsDiagnosticAnalyzerSuppressedWithExceptionInSupportedDiagnostic { // Verify IsDiagnosticAnalyzerSuppressed does not throw an exception when 'onAnalyzerException' is null. var analyzer = new AnalyzerThatThrowsInSupportedDiagnostics(); - var options = TestOptions.ReleaseDll; - _ = CompilationWithAnalyzers.IsDiagnosticAnalyzerSuppressed(analyzer, options, onAnalyzerException: null); + _ = CompilationWithAnalyzers.IsDiagnosticAnalyzerSuppressed(analyzer, s_dllWithMaxWarningLevel, onAnalyzerException: null); } } } diff --git a/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs b/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs index e46d735d70c22..1b680d785823e 100644 --- a/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs @@ -4,6 +4,7 @@ using System.Collections.Immutable; using System.IO; +using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; @@ -13,6 +14,9 @@ namespace Microsoft.CodeAnalysis.UnitTests { public sealed class ShadowCopyAnalyzerAssemblyLoaderTests : TestBase { + private const int MaxWarningLevel = 9999; + private static readonly CSharpCompilationOptions s_dllWithMaxWarningLevel = new(OutputKind.DynamicallyLinkedLibrary, warningLevel: MaxWarningLevel); + [Fact, WorkItem(32226, "https://github.com/dotnet/roslyn/issues/32226")] public void LoadWithDependency() { @@ -52,9 +56,9 @@ public abstract class AbstractTestAnalyzer : DiagnosticAnalyzer public override void Initialize(AnalysisContext context) { throw new NotImplementedException(); } }"; - var analyzerDependencyCompilation = CSharp.CSharpCompilation.Create( + var analyzerDependencyCompilation = CSharpCompilation.Create( "AnalyzerDependency", - new SyntaxTree[] { CSharp.SyntaxFactory.ParseSyntaxTree(analyzerDependencySource) }, + new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(analyzerDependencySource) }, new MetadataReference[] { TestMetadata.NetStandard20.mscorlib, @@ -63,7 +67,7 @@ public abstract class AbstractTestAnalyzer : DiagnosticAnalyzer MetadataReference.CreateFromFile(immutable.Path), MetadataReference.CreateFromFile(microsoftCodeAnalysis.Path) }, - new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + s_dllWithMaxWarningLevel); return directory.CreateDirectory("AnalyzerDependency").CreateFile("AnalyzerDependency.dll").WriteAllBytes(analyzerDependencyCompilation.EmitToArray()); } @@ -79,9 +83,9 @@ public sealed class TestAnalyzer : AbstractTestAnalyzer { private static string SomeString2 = AbstractTestAnalyzer.SomeString; }"; - var analyzerMainCompilation = CSharp.CSharpCompilation.Create( + var analyzerMainCompilation = CSharpCompilation.Create( "AnalyzerMain", - new SyntaxTree[] { CSharp.SyntaxFactory.ParseSyntaxTree(analyzerMainSource) }, + new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(analyzerMainSource) }, new MetadataReference[] { TestMetadata.NetStandard20.mscorlib, @@ -91,7 +95,7 @@ public sealed class TestAnalyzer : AbstractTestAnalyzer MetadataReference.CreateFromFile(microsoftCodeAnalysis.Path), MetadataReference.CreateFromFile(analyzerDependency.Path) }, - new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + s_dllWithMaxWarningLevel); return directory.CreateDirectory("AnalyzerMain").CreateFile("AnalyzerMain.dll").WriteAllBytes(analyzerMainCompilation.EmitToArray()); } diff --git a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs index 73a3341d75582..dfa7bedbcb555 100644 --- a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs +++ b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs @@ -14,6 +14,8 @@ namespace Microsoft.CodeAnalysis.CSharp.Test.Utilities { public static class TestOptions { + private const int MaxWarningLevel = 9999; + public static readonly CSharpParseOptions Regular = new CSharpParseOptions(kind: SourceCodeKind.Regular, documentationMode: DocumentationMode.Parse); public static readonly CSharpParseOptions Script = Regular.WithKind(SourceCodeKind.Script); public static readonly CSharpParseOptions Regular6 = Regular.WithLanguageVersion(LanguageVersion.CSharp6); @@ -47,34 +49,33 @@ public static class TestOptions public static readonly CSharpParseOptions RegularWithoutPatternCombinators = Regular8; public static readonly CSharpParseOptions RegularWithPatternCombinators = RegularPreview; - public static readonly CSharpCompilationOptions ReleaseDll = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5); - public static readonly CSharpCompilationOptions ReleaseExe = new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5); + public static readonly CSharpCompilationOptions ReleaseDll = CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, OptimizationLevel.Release); + public static readonly CSharpCompilationOptions ReleaseExe = CreateTestOptions(OutputKind.ConsoleApplication, OptimizationLevel.Release); - public static readonly CSharpCompilationOptions ReleaseDebugDll = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5). - WithDebugPlusMode(true); + public static readonly CSharpCompilationOptions ReleaseDebugDll = ReleaseDll.WithDebugPlusMode(true); - public static readonly CSharpCompilationOptions ReleaseDebugExe = new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5). - WithDebugPlusMode(true); + public static readonly CSharpCompilationOptions ReleaseDebugExe = ReleaseExe.WithDebugPlusMode(true); - public static readonly CSharpCompilationOptions DebugDll = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel: OptimizationLevel.Debug).WithWarningLevel(5); - public static readonly CSharpCompilationOptions DebugExe = new CSharpCompilationOptions(OutputKind.ConsoleApplication, optimizationLevel: OptimizationLevel.Debug).WithWarningLevel(5); + public static readonly CSharpCompilationOptions DebugDll = CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, OptimizationLevel.Debug); + public static readonly CSharpCompilationOptions DebugExe = CreateTestOptions(OutputKind.ConsoleApplication, OptimizationLevel.Debug); + public static readonly CSharpCompilationOptions DebugWindowsRuntimeApp = CreateTestOptions(OutputKind.WindowsRuntimeApplication, OptimizationLevel.Debug); - public static readonly CSharpCompilationOptions ReleaseWinMD = new CSharpCompilationOptions(OutputKind.WindowsRuntimeMetadata, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5); - public static readonly CSharpCompilationOptions DebugWinMD = new CSharpCompilationOptions(OutputKind.WindowsRuntimeMetadata, optimizationLevel: OptimizationLevel.Debug).WithWarningLevel(5); + public static readonly CSharpCompilationOptions ReleaseWinMD = CreateTestOptions(OutputKind.WindowsRuntimeMetadata, OptimizationLevel.Release); + public static readonly CSharpCompilationOptions DebugWinMD = CreateTestOptions(OutputKind.WindowsRuntimeMetadata, OptimizationLevel.Debug); - public static readonly CSharpCompilationOptions ReleaseModule = new CSharpCompilationOptions(OutputKind.NetModule, optimizationLevel: OptimizationLevel.Release).WithWarningLevel(5); - public static readonly CSharpCompilationOptions DebugModule = new CSharpCompilationOptions(OutputKind.NetModule, optimizationLevel: OptimizationLevel.Debug).WithWarningLevel(5); + public static readonly CSharpCompilationOptions ReleaseModule = CreateTestOptions(OutputKind.NetModule, OptimizationLevel.Release); + public static readonly CSharpCompilationOptions DebugModule = CreateTestOptions(OutputKind.NetModule, OptimizationLevel.Debug); - public static readonly CSharpCompilationOptions UnsafeReleaseDll = ReleaseDll.WithAllowUnsafe(true).WithWarningLevel(5); - public static readonly CSharpCompilationOptions UnsafeReleaseExe = ReleaseExe.WithAllowUnsafe(true).WithWarningLevel(5); + public static readonly CSharpCompilationOptions UnsafeReleaseDll = ReleaseDll.WithAllowUnsafe(true); + public static readonly CSharpCompilationOptions UnsafeReleaseExe = ReleaseExe.WithAllowUnsafe(true); - public static readonly CSharpCompilationOptions UnsafeDebugDll = DebugDll.WithAllowUnsafe(true).WithWarningLevel(5); - public static readonly CSharpCompilationOptions UnsafeDebugExe = DebugExe.WithAllowUnsafe(true).WithWarningLevel(5); + public static readonly CSharpCompilationOptions UnsafeDebugDll = DebugDll.WithAllowUnsafe(true); + public static readonly CSharpCompilationOptions UnsafeDebugExe = DebugExe.WithAllowUnsafe(true); - public static readonly CSharpCompilationOptions SigningReleaseDll = ReleaseDll.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider).WithWarningLevel(5); - public static readonly CSharpCompilationOptions SigningReleaseExe = ReleaseExe.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider).WithWarningLevel(5); - public static readonly CSharpCompilationOptions SigningReleaseModule = ReleaseModule.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider).WithWarningLevel(5); - public static readonly CSharpCompilationOptions SigningDebugDll = DebugDll.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider).WithWarningLevel(5); + public static readonly CSharpCompilationOptions SigningReleaseDll = ReleaseDll.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider); + public static readonly CSharpCompilationOptions SigningReleaseExe = ReleaseExe.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider); + public static readonly CSharpCompilationOptions SigningReleaseModule = ReleaseModule.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider); + public static readonly CSharpCompilationOptions SigningDebugDll = DebugDll.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider); public static readonly EmitOptions NativePdbEmit = EmitOptions.Default.WithDebugInformationFormat(DebugInformationFormat.Pdb); @@ -143,6 +144,8 @@ public static CSharpCompilationOptions WithSpecificDiagnosticOptions(this CSharp { return options.WithSpecificDiagnosticOptions(ImmutableDictionary.Empty.Add(key1, value).Add(key2, value)); } + + private static CSharpCompilationOptions CreateTestOptions(OutputKind outputKind, OptimizationLevel optimizationLevel) => new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel, warningLevel: MaxWarningLevel); } } From f2114f2bc8c0d58881875264398ff2bfac9b6941 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Mon, 24 Aug 2020 14:19:06 +0200 Subject: [PATCH 09/39] Update MetadataMemberTests.cs --- .../Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs index dd7cad49a7ba8..cdda714223e55 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs @@ -794,14 +794,14 @@ public class C Assert.Empty(c.GetMembers("P3")); CompileAndVerify(compilation); - compilation = compilation.WithOptions(TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All)); + compilation = compilation.WithOptions(TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All)); c = compilation.GetTypeByMetadataName("C"); Assert.NotEmpty(c.GetMembers("P1")); Assert.NotEmpty(c.GetMembers("P2")); Assert.NotEmpty(c.GetMembers("P3")); CompileAndVerify(compilation); - compilation = compilation.WithOptions(TestOptions.ReleaseDll.WithMetadataImportOptions((MetadataImportOptions)byte.MaxValue)); + compilation = compilation.WithOptions(TestOptions.DebugDll.WithMetadataImportOptions((MetadataImportOptions)byte.MaxValue)); c = compilation.GetTypeByMetadataName("C"); Assert.NotEmpty(c.GetMembers("P1")); Assert.NotEmpty(c.GetMembers("P2")); From 54b0c34c2838bb287b3dcd6202c6d16417fdc92f Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Mon, 24 Aug 2020 14:25:55 +0200 Subject: [PATCH 10/39] Update AssemblyAndNamespaceTests.cs --- .../CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs index 393ad2c9f703b..1169cf4670626 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs @@ -112,11 +112,11 @@ struct S {} } } "; - var comp1 = CSharpCompilation.Create(assemblyName: "Test", options: TestOptions.ReleaseExe, + var comp1 = CSharpCompilation.Create(assemblyName: "Test", options: TestOptions.DebugExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text) }, references: new MetadataReference[] { }); var compRef = new CSharpCompilationReference(comp1); - var comp = CSharpCompilation.Create(assemblyName: "Test1", options: TestOptions.ReleaseExe, + var comp = CSharpCompilation.Create(assemblyName: "Test1", options: TestOptions.DebugExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text1), SyntaxFactory.ParseSyntaxTree(text2) }, references: new MetadataReference[] { compRef }); From 368a08f339c7db208b00e3e99e0be79b83c22c56 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Mon, 24 Aug 2020 14:27:09 +0200 Subject: [PATCH 11/39] Update AssemblyAndNamespaceTests.cs --- .../Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs index 1169cf4670626..c6358be71010a 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/AssemblyAndNamespaceTests.cs @@ -159,7 +159,7 @@ class C : NN.B { } var comp1 = CreateCompilation(text); var compRef = new CSharpCompilationReference(comp1); - var comp = CSharpCompilation.Create(assemblyName: "Test1", options: TestOptions.ReleaseExe, + var comp = CSharpCompilation.Create(assemblyName: "Test1", options: TestOptions.DebugExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text1), SyntaxFactory.ParseSyntaxTree(text2) }, references: new MetadataReference[] { compRef }); @@ -246,13 +246,13 @@ struct SGoo {} } "; - var comp1 = CSharpCompilation.Create(assemblyName: "Test1", options: TestOptions.ReleaseExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text1) }, references: new MetadataReference[] { }); - var comp2 = CSharpCompilation.Create(assemblyName: "Test2", options: TestOptions.ReleaseExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text2) }, references: new MetadataReference[] { }); + var comp1 = CSharpCompilation.Create(assemblyName: "Test1", options: TestOptions.DebugExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text1) }, references: new MetadataReference[] { }); + var comp2 = CSharpCompilation.Create(assemblyName: "Test2", options: TestOptions.DebugExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text2) }, references: new MetadataReference[] { }); var compRef1 = new CSharpCompilationReference(comp1); var compRef2 = new CSharpCompilationReference(comp2); - var comp = CSharpCompilation.Create(assemblyName: "Test3", options: TestOptions.ReleaseExe, + var comp = CSharpCompilation.Create(assemblyName: "Test3", options: TestOptions.DebugExe, syntaxTrees: new SyntaxTree[] { SyntaxFactory.ParseSyntaxTree(text3) }, references: new MetadataReference[] { compRef1, compRef2 }); From 49709b969fbbfda0bb980c40b1ccdd099d594418 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Mon, 24 Aug 2020 14:28:53 +0200 Subject: [PATCH 12/39] Update MetadataMemberTests.cs --- .../Symbol/Symbols/Metadata/MetadataMemberTests.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs index cdda714223e55..8a8e2b974199e 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Metadata/MetadataMemberTests.cs @@ -682,7 +682,7 @@ public void TestMetadataImportOptions_01() Diagnostic(ErrorCode.ERR_BadCompilationOptionValue).WithArguments("MetadataImportOptions", "255").WithLocation(1, 1) }; - var options = TestOptions.ReleaseDll; + var options = TestOptions.DebugDll; Assert.Equal(MetadataImportOptions.Public, options.MetadataImportOptions); options.VerifyErrors(); @@ -724,7 +724,7 @@ public class C "; var compilation0 = CreateCompilation(source); - options = TestOptions.ReleaseDll; + options = TestOptions.DebugDll; var compilation = CreateCompilation("", options: options, references: new[] { compilation0.EmitToImageReference() }); var c = compilation.GetTypeByMetadataName("C"); Assert.NotEmpty(c.GetMembers("P1")); @@ -764,16 +764,16 @@ public void TestMetadataImportOptions_02() Diagnostic(ErrorCode.ERR_BadCompilationOptionValue).WithArguments("MetadataImportOptions", "255").WithLocation(1, 1) }; - var options = TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.Internal); + var options = TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.Internal); Assert.Equal(MetadataImportOptions.Internal, options.MetadataImportOptions); options.VerifyErrors(); - options = TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.All); + options = TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.All); Assert.Equal(MetadataImportOptions.All, options.MetadataImportOptions); options.VerifyErrors(); - options = TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.Public); + options = TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.Public); Assert.Equal(MetadataImportOptions.Public, options.MetadataImportOptions); options.VerifyErrors(); - options = TestOptions.ReleaseDll.WithMetadataImportOptions((MetadataImportOptions)byte.MaxValue); + options = TestOptions.DebugDll.WithMetadataImportOptions((MetadataImportOptions)byte.MaxValue); Assert.Equal((MetadataImportOptions)byte.MaxValue, options.MetadataImportOptions); options.VerifyErrors(expectedDiagnostics); @@ -787,7 +787,7 @@ public class C "; var compilation0 = CreateCompilation(source); - var compilation = CreateCompilation("", options: TestOptions.ReleaseDll.WithMetadataImportOptions(MetadataImportOptions.Internal), references: new[] { compilation0.EmitToImageReference() }); + var compilation = CreateCompilation("", options: TestOptions.DebugDll.WithMetadataImportOptions(MetadataImportOptions.Internal), references: new[] { compilation0.EmitToImageReference() }); var c = compilation.GetTypeByMetadataName("C"); Assert.NotEmpty(c.GetMembers("P1")); Assert.NotEmpty(c.GetMembers("P2")); From d773bedd02c33c1b88074e8cb4e73f813896ec45 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 24 Aug 2020 12:45:30 +0000 Subject: [PATCH 13/39] More work --- .../CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs | 2 +- .../CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs | 4 ++-- .../Test/Symbol/Symbols/Source/ExternAliasTests.cs | 2 +- .../CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs | 6 +++--- .../CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs | 4 ++-- .../CSharp/Test/WinRT/Metadata/WinMdEventTests.cs | 9 +++------ 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs index ac2012dd61d23..5e2c165406d99 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/ExtensionMethodTests.cs @@ -2415,7 +2415,7 @@ public void UsingInScript() var compilation = CSharpCompilation.Create( assemblyName: GetUniqueName(), - options: new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithScriptClassName("Script"), + options: TestOptions.DebugExe.WithScriptClassName("Script"), syntaxTrees: new[] { tree }, references: new[] { MscorlibRef, LinqAssemblyRef }); diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs index 71732b7aede18..c5eca8aca50c1 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/GenericConstraintTests.cs @@ -1005,7 +1005,7 @@ private C() { } fixed int F[C>.G]; const int G = 1; }"; - CreateCompilation(source, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true)).VerifyDiagnostics( + CreateCompilation(source, options: TestOptions.UnsafeDebugDll).VerifyDiagnostics( // (4,15): error CS1642: Fixed size buffer fields may only be members of structs Diagnostic(ErrorCode.ERR_FixedNotInStruct, "F").WithLocation(4, 15), // (4,19): error CS0310: 'C' must be a non-abstract type with a public parameterless constructor in order to use it as parameter 'T' in the generic type or method 'C' @@ -5664,7 +5664,7 @@ public class Base2 : Base1 { public override void Goo(G d) { Console.WriteLine(""Base2""); } }", - compilationOptions: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + compilationOptions: TestOptions.DebugDll); var csVerifier = CompileAndVerify(csCompilation); csVerifier.VerifyDiagnostics(); diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExternAliasTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExternAliasTests.cs index 7de60b3fb44ed..ba38bb9523542 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExternAliasTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/ExternAliasTests.cs @@ -95,7 +95,7 @@ public void ExternAliasInScript() extern alias Bar; Bar::NS.Goo d = new Bar::NS.Goo(); "; - var comp = CreateCompilationWithMscorlib45(src, options: new CSharpCompilationOptions(OutputKind.ConsoleApplication), parseOptions: TestOptions.Script); + var comp = CreateCompilationWithMscorlib45(src, options: TestOptions.DebugExe, parseOptions: TestOptions.Script); comp = comp.AddReferences(Goo1, Goo2); comp.VerifyDiagnostics(); } diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs index c2b267880c690..fcb44eb25b354 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/Source/PropertyTests.cs @@ -2598,7 +2598,7 @@ public interface IA string M2(); }"; var refComp = CSharpCompilation.Create("DLL", - options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary), + options: TestOptions.DebugDll, syntaxTrees: new[] { SyntaxFactory.ParseSyntaxTree(refSrc) }, references: new MetadataReference[] { MscorlibRef }); @@ -2690,7 +2690,7 @@ public interface IA }"; refComp = CSharpCompilation.Create("DLL", - options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary), + options: TestOptions.DebugDll, syntaxTrees: new[] { SyntaxFactory.ParseSyntaxTree(refSrc) }, references: new[] { MscorlibRef }); @@ -2889,7 +2889,7 @@ static void Main(string[] args) } } "; - CreateCompilationWithMscorlibAndSpan(text, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true)).VerifyDiagnostics( + CreateCompilationWithMscorlibAndSpan(text, options: TestOptions.UnsafeDebugDll).VerifyDiagnostics( // (4,30): error CS8346: Conversion of a stackalloc expression of type 'int' to type 'int*' is not possible. // int* property { get; } = stackalloc int[256]; Diagnostic(ErrorCode.ERR_StackAllocConversionNotPossible, "stackalloc int[256]").WithArguments("int", "int*").WithLocation(4, 30) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs index 690b62c7f3a42..eca6b72373b3a 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs @@ -20381,7 +20381,7 @@ .assembly extern D2 var forwarderCompilation = CreateEmptyCompilation( source: string.Empty, references: new MetadataReference[] { ilModuleReference }, - options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary), + options: TestOptions.DebugDll, assemblyName: "Forwarder"); var csSource = @" @@ -20446,7 +20446,7 @@ .assembly extern D4 var forwarderCompilation = CreateEmptyCompilation( source: string.Empty, references: new MetadataReference[] { module1Reference, module2Reference }, - options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary), + options: TestOptions.DebugDll, assemblyName: "Forwarder"); var csSource = @" diff --git a/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs b/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs index bfce3edd4da4c..163cc330bec4d 100644 --- a/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs +++ b/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs @@ -236,10 +236,7 @@ public interface I _eventLibRef = CreateEmptyCompilation( eventLibSrc, references: new[] { MscorlibRef_v4_0_30316_17626, SystemCoreRef_v4_0_30319_17929 }, - options: - new CSharpCompilationOptions( - OutputKind.WindowsRuntimeMetadata, - allowUnsafe: true), + options: TestOptions.DebugWinMD.WithAllowUnsafe(true), assemblyName: "EventLibrary").EmitToImageReference(); } @@ -311,7 +308,7 @@ static void Main() MscorlibRef_v4_0_30316_17626, _eventLibRef, }, - options: new CSharpCompilationOptions(OutputKind.NetModule, allowUnsafe: true)); + options: TestOptions.DebugModule.WithAllowUnsafe(true)); var dynamicCommonRef = dynamicCommon.EmitToImageReference(expectedWarnings: new[] { @@ -2912,7 +2909,7 @@ interface I foreach (OutputKind kind in Enum.GetValues(typeof(OutputKind))) { - var comp = CreateEmptyCompilation(source, WinRtRefs, new CSharpCompilationOptions(kind)); + var comp = CreateEmptyCompilation(source, WinRtRefs, TestOptions.DebugDll.WithOutputKind(kind)); comp.VerifyDiagnostics(); var @class = comp.GlobalNamespace.GetMember("C"); From bc9d1c02cfda7fc58b103a0876d456210786dcff Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 24 Aug 2020 12:48:07 +0000 Subject: [PATCH 14/39] More --- .../Emit/PDB/CSharpDeterministicBuildCompilationTests.cs | 2 +- .../CSharp/Test/Semantic/Semantics/NameOfTests.cs | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs index eae3305358b7d..31752cb01df7c 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs @@ -235,7 +235,7 @@ private static IEnumerable GetCompilationOptions() delaySign: null, platform: Platform.AnyCpu, generalDiagnosticOption: ReportDiagnostic.Default, - warningLevel: 5, + warningLevel: 5, // Question: Do you want to use 9999 here instead of 5? or this is explicitly 5 for some reason? specificDiagnosticOptions: null, concurrentBuild: true, deterministic: true, diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NameOfTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NameOfTests.cs index b81f7d7e7f04f..6397a055df3ac 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NameOfTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NameOfTests.cs @@ -1209,7 +1209,7 @@ public static string GetFromExternal() { } } "; - var compilation = CreateCompilationWithMscorlib45(source, null, new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithAllowUnsafe(true)); + var compilation = CreateCompilationWithMscorlib45(source, null, TestOptions.UnsafeDebugExe); CompileAndVerify(compilation, expectedOutput: "MessageType x MessageType").VerifyDiagnostics(); } @@ -1248,7 +1248,7 @@ public static string GetFromExternal() { } }"; var compilation = CreateCompilationWithMscorlib45(source, null, - new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary).WithAllowUnsafe(true)).VerifyDiagnostics( + TestOptions.UnsafeDebugDll).VerifyDiagnostics( // (14,19): error CS1666: You cannot use fixed size buffers contained in unfixed expressions. Try using the fixed statement. // return nameof(MessageType); Diagnostic(ErrorCode.ERR_FixedBufferNotFixed, "MessageType").WithLocation(14, 19), @@ -1292,7 +1292,7 @@ public static void Main(string[] args) } } "; - var compilation = CreateCompilationWithMscorlib45(source, null, new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithAllowUnsafe(true)); + var compilation = CreateCompilationWithMscorlib45(source, null, TestOptions.UnsafeDebugExe); CompileAndVerify(compilation, expectedOutput: "normalField fixedField fixedField").VerifyDiagnostics(); } @@ -1324,7 +1324,7 @@ public static void Main(string[] args) } } "; - var compilation = CreateCompilationWithMscorlib45(source, null, new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithAllowUnsafe(true)); + var compilation = CreateCompilationWithMscorlib45(source, null, TestOptions.UnsafeDebugExe); CompileAndVerify(compilation, expectedOutput: "normalField fixedField").VerifyDiagnostics(); } From 39c910668866a1f0a215c3bec703ae98d28b29b1 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 24 Aug 2020 13:02:29 +0000 Subject: [PATCH 15/39] More --- .../Semantics/StackAllocInitializerTests.cs | 2 +- .../Semantics/StackAllocSpanExpressionsTests.cs | 2 +- .../Test/Symbol/Compilation/CompilationAPITests.cs | 14 +++++++------- .../Symbol/Compilation/ReferenceManagerTests.cs | 2 +- .../SemanticModelGetDeclaredSymbolAPITests.cs | 2 +- .../CSharp/Test/Symbol/DeclarationTests.cs | 8 ++++---- .../Test/Syntax/Parsing/ParserErrorMessageTests.cs | 2 +- .../CSharp/Test/WinRT/Metadata/WinMdEventTests.cs | 8 ++++---- .../AnalyzerConsistencyCheckerTests.cs | 4 +++- 9 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/StackAllocInitializerTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/StackAllocInitializerTests.cs index 5d22c0f7e3734..ec52de3d80a46 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/StackAllocInitializerTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/StackAllocInitializerTests.cs @@ -1579,7 +1579,7 @@ void M() } } "; - CreateCompilation(test, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true)).VerifyDiagnostics( + CreateCompilation(test, options: TestOptions.UnsafeDebugDll).VerifyDiagnostics( // (6,15): error CS0283: The type 'int*' cannot be declared const // const int* p1 = stackalloc int[1] { 1 }; Diagnostic(ErrorCode.ERR_BadConstType, "int*").WithArguments("int*").WithLocation(6, 15), diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/StackAllocSpanExpressionsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/StackAllocSpanExpressionsTests.cs index 585f0f03f868d..9379a22784ca1 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/StackAllocSpanExpressionsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/StackAllocSpanExpressionsTests.cs @@ -466,7 +466,7 @@ void M() } } "; - CreateCompilation(test, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true)).VerifyDiagnostics( + CreateCompilation(test, options: TestOptions.UnsafeDebugDll).VerifyDiagnostics( // (6,15): error CS0283: The type 'int*' cannot be declared const // const int* p = stackalloc int[1]; Diagnostic(ErrorCode.ERR_BadConstType, "int*").WithArguments("int*").WithLocation(6, 15)); diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs index 9bd32a4dc951f..4e2f5c2c0831d 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs @@ -229,7 +229,7 @@ public void WarningLevelRespectedForLexerWarnings() [Fact] public void PublicSignWithRelativeKeyPath() { - var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary) + var options = TestOptions.DebugDll .WithPublicSign(true).WithCryptoKeyFile("test.snk"); var comp = CSharpCompilation.Create("test", options: options); comp.VerifyDiagnostics( @@ -477,9 +477,9 @@ public void Emit_BadArgs() [Fact] public void ReferenceAPITest() { - var opt = new CSharpCompilationOptions(OutputKind.ConsoleApplication); + var opt = TestOptions.DebugExe; // Create Compilation takes two args - var comp = CSharpCompilation.Create("Compilation", options: new CSharpCompilationOptions(OutputKind.ConsoleApplication)); + var comp = CSharpCompilation.Create("Compilation", options: TestOptions.DebugExe); var ref1 = Net451.mscorlib; var ref2 = Net451.System; var ref3 = new TestMetadataReference(fullPath: @"c:\xml.bms"); @@ -1977,10 +1977,10 @@ public void ReferenceManagerReuse_WithOptions() c2 = c1.WithOptions(TestOptions.ReleaseDll); Assert.False(c1.ReferenceManagerEquals(c2)); - c2 = c1.WithOptions(new CSharpCompilationOptions(OutputKind.WindowsApplication)); + c2 = c1.WithOptions(new CSharpCompilationOptions(OutputKind.WindowsApplication)); // Do you want to introduce a new DebugWindowsApplication field in TestOptions? Assert.False(c1.ReferenceManagerEquals(c2)); - c2 = c1.WithOptions(new CSharpCompilationOptions(OutputKind.NetModule).WithAllowUnsafe(true)); + c2 = c1.WithOptions(TestOptions.DebugModule.WithAllowUnsafe(true)); Assert.True(c1.ReferenceManagerEquals(c2)); } @@ -2197,7 +2197,7 @@ public void MetadataConsistencyWhileEvolvingCompilation() var c1 = CreateEmptyCompilation("public class Main { public static C C; }", new[] { MscorlibRef, reference, reference }); var c2 = c1.WithAssemblyName("c2"); var c3 = c2.AddSyntaxTrees(Parse("public class Main2 { public static int a; }")); - var c4 = c3.WithOptions(new CSharpCompilationOptions(OutputKind.NetModule)); + var c4 = c3.WithOptions(TestOptions.DebugModule); var c5 = c4.WithReferences(new[] { MscorlibRef, reference }); c3.VerifyDiagnostics(); @@ -2372,7 +2372,7 @@ public void ConsistentParseOptions() var tree3 = SyntaxFactory.ParseSyntaxTree("", CSharpParseOptions.Default.WithLanguageVersion(LanguageVersion.CSharp5)); var assemblyName = GetUniqueName(); - var compilationOptions = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary); + var compilationOptions = TestOptions.DebugDll; CSharpCompilation.Create(assemblyName, new[] { tree1, tree2 }, new[] { MscorlibRef }, compilationOptions); Assert.Throws(() => { diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/ReferenceManagerTests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/ReferenceManagerTests.cs index c54d76a19425a..e7accaabe4d22 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/ReferenceManagerTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/ReferenceManagerTests.cs @@ -746,7 +746,7 @@ public static void Main(string[] args) var r2 = AssemblyMetadata.CreateFromImage(ResourcesNet451.SystemCore).GetReference(filePath: @"c:\temp\aa.dll", display: "System.Core.v4_0_30319.dll"); var r2_SysCore = r2.WithAliases(new[] { "SysCore" }); - var compilation = CreateEmptyCompilation(tree, new[] { MscorlibRef, r1, r2_SysCore }, new CSharpCompilationOptions(OutputKind.ConsoleApplication), assemblyName: "Test"); + var compilation = CreateEmptyCompilation(tree, new[] { MscorlibRef, r1, r2_SysCore }, TestOptions.DebugExe, assemblyName: "Test"); CompileAndVerify(compilation, expectedOutput: "k"); } diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs index ec8d4e731c02c..90771f5b173c5 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/SemanticModelGetDeclaredSymbolAPITests.cs @@ -2747,7 +2747,7 @@ public static void M() var compilation = CSharpCompilation.Create( assemblyName: "Test", - options: new CSharpCompilationOptions(OutputKind.ConsoleApplication).WithScriptClassName("Script"), + options: TestOptions.DebugExe.WithScriptClassName("Script"), syntaxTrees: new[] { tree }, references: new[] { MscorlibRef }); diff --git a/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs b/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs index 287e34a95e15d..6858de37ac686 100644 --- a/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/DeclarationTests.cs @@ -61,8 +61,8 @@ partial class D var tree2 = SyntaxFactory.ParseSyntaxTree(text2); Assert.NotNull(tree1); Assert.NotNull(tree2); - var decl1 = DeclarationTreeBuilder.ForTree(tree1, new CSharpCompilationOptions(OutputKind.ConsoleApplication).ScriptClassName, isSubmission: false); - var decl2 = DeclarationTreeBuilder.ForTree(tree2, new CSharpCompilationOptions(OutputKind.ConsoleApplication).ScriptClassName, isSubmission: false); + var decl1 = DeclarationTreeBuilder.ForTree(tree1, TestOptions.DebugExe.ScriptClassName, isSubmission: false); + var decl2 = DeclarationTreeBuilder.ForTree(tree2, TestOptions.DebugExe.ScriptClassName, isSubmission: false); Assert.NotNull(decl1); Assert.NotNull(decl2); Assert.Equal(string.Empty, decl1.Name); @@ -230,8 +230,8 @@ partial class D var tree2 = SyntaxFactory.ParseSyntaxTree(text2); Assert.NotNull(tree1); Assert.NotNull(tree2); - var decl1 = Lazy(DeclarationTreeBuilder.ForTree(tree1, new CSharpCompilationOptions(OutputKind.ConsoleApplication).ScriptClassName, isSubmission: false)); - var decl2 = Lazy(DeclarationTreeBuilder.ForTree(tree2, new CSharpCompilationOptions(OutputKind.ConsoleApplication).ScriptClassName, isSubmission: false)); + var decl1 = Lazy(DeclarationTreeBuilder.ForTree(tree1, TestOptions.DebugExe.ScriptClassName, isSubmission: false)); + var decl2 = Lazy(DeclarationTreeBuilder.ForTree(tree2, TestOptions.DebugExe.ScriptClassName, isSubmission: false)); var table = DeclarationTable.Empty; table = table.AddRootDeclaration(decl1); diff --git a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs index adbadfa505740..c8f1bdaaa7c77 100644 --- a/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs +++ b/src/Compilers/CSharp/Test/Syntax/Parsing/ParserErrorMessageTests.cs @@ -4819,7 +4819,7 @@ void M() } } "; - CreateCompilation(test, options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe: true)).VerifyDiagnostics( + CreateCompilation(test, options: TestOptions.UnsafeDebugDll).VerifyDiagnostics( // (6,15): error CS0283: The type 'int*' cannot be declared const // const int* p = stackalloc int[1]; Diagnostic(ErrorCode.ERR_BadConstType, "int*").WithArguments("int*").WithLocation(6, 15) diff --git a/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs b/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs index 163cc330bec4d..7b4031d23c7b9 100644 --- a/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs +++ b/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs @@ -2953,7 +2953,7 @@ public event System.Action WinRT foreach (OutputKind kind in new[] { OutputKind.DynamicallyLinkedLibrary, OutputKind.WindowsRuntimeMetadata }) { - var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { ilRef }), new CSharpCompilationOptions(kind)); + var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { ilRef }), TestOptions.DebugDll.WithOutputKind(kind)); comp.VerifyDiagnostics(); var @class = comp.GlobalNamespace.GetMember("C"); @@ -3022,7 +3022,7 @@ public override event System.Action WinRT foreach (OutputKind kind in new[] { OutputKind.DynamicallyLinkedLibrary, OutputKind.WindowsRuntimeMetadata }) { - var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { interfaceILRef, baseILRef }), new CSharpCompilationOptions(kind)); + var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { interfaceILRef, baseILRef }), TestOptions.DebugDll.WithOutputKind(kind)); comp.VerifyDiagnostics( // (40,41): error CS1991: 'OverrideAndImplIncorrectly.WinRT' cannot implement 'Interface.WinRT' because 'Interface.WinRT' is a Windows Runtime event and 'OverrideAndImplIncorrectly.WinRT' is a regular .NET event. // public override event System.Action WinRT @@ -3088,7 +3088,7 @@ event System.Action Interface.WinRT foreach (OutputKind kind in new[] { OutputKind.DynamicallyLinkedLibrary, OutputKind.WindowsRuntimeMetadata }) { - var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { ilRef }), new CSharpCompilationOptions(kind)); + var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { ilRef }), TestOptions.DebugDll.WithOutputKind(kind)); comp.VerifyDiagnostics(); var @class = comp.GlobalNamespace.GetMember("C"); @@ -3283,7 +3283,7 @@ static void Main() { } foreach (OutputKind kind in new[] { OutputKind.DynamicallyLinkedLibrary, OutputKind.WindowsRuntimeMetadata }) { - var comp = CreateEmptyCompilation(source, WinRtRefs, new CSharpCompilationOptions(kind)); + var comp = CreateEmptyCompilation(source, WinRtRefs, TestOptions.DebugDll.WithOutputKind(kind)); comp.VerifyDiagnostics( // (10,25): warning CS0067: The event 'C.F' is never used // event System.Action F; diff --git a/src/Compilers/Server/VBCSCompilerTests/AnalyzerConsistencyCheckerTests.cs b/src/Compilers/Server/VBCSCompilerTests/AnalyzerConsistencyCheckerTests.cs index b49c6b0fc4a10..1ba1159e6dd0a 100644 --- a/src/Compilers/Server/VBCSCompilerTests/AnalyzerConsistencyCheckerTests.cs +++ b/src/Compilers/Server/VBCSCompilerTests/AnalyzerConsistencyCheckerTests.cs @@ -18,6 +18,8 @@ namespace Microsoft.CodeAnalysis.CompilerServer.UnitTests { public class AnalyzerConsistencyCheckerTests : TestBase { + private const int MaxWarningLevel = 9999; + [Fact] public void MissingReference() { @@ -98,7 +100,7 @@ public void NetstandardIgnored() name, new[] { SyntaxFactory.ParseSyntaxTree(@"class C {}") }, references: new MetadataReference[] { MetadataReference.CreateFromImage(TestMetadata.ResourcesNetStandard20.netstandard) }, - options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); + options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: MaxWarningLevel)); var compFile = directory.CreateFile(name); comp.Emit(compFile.Path); From f5a47703e80d385573ed151ee47537d29733430c Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Mon, 24 Aug 2020 17:17:39 +0200 Subject: [PATCH 16/39] Update InterpolationTests.cs --- .../CSharp/Test/Semantic/Semantics/InterpolationTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index ee069549453b7..4dbfeda658ee1 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -2,6 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. +using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using System.Linq; From 2ce9c1e8adca0909f9a0e449e4d6187532a9569d Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 26 Aug 2020 13:58:02 +0200 Subject: [PATCH 17/39] More fixes --- .../Emit/PDB/CSharpDeterministicBuildCompilationTests.cs | 2 +- .../CSharp/Test/Symbol/Compilation/CompilationAPITests.cs | 2 +- .../Analyzers/AnalyzerFileReferenceAppDomainTests.cs | 8 +++----- src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs | 5 ++--- .../Diagnostics/CompilationWithAnalyzersTests.cs | 4 ++-- .../ShadowCopyAnalyzerAssemblyLoaderTests.cs | 4 ++-- src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs | 5 +++++ 7 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs index 31752cb01df7c..eae3305358b7d 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs @@ -235,7 +235,7 @@ private static IEnumerable GetCompilationOptions() delaySign: null, platform: Platform.AnyCpu, generalDiagnosticOption: ReportDiagnostic.Default, - warningLevel: 5, // Question: Do you want to use 9999 here instead of 5? or this is explicitly 5 for some reason? + warningLevel: 5, specificDiagnosticOptions: null, concurrentBuild: true, deterministic: true, diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs index 4e2f5c2c0831d..8c25f520da8f8 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs @@ -1977,7 +1977,7 @@ public void ReferenceManagerReuse_WithOptions() c2 = c1.WithOptions(TestOptions.ReleaseDll); Assert.False(c1.ReferenceManagerEquals(c2)); - c2 = c1.WithOptions(new CSharpCompilationOptions(OutputKind.WindowsApplication)); // Do you want to introduce a new DebugWindowsApplication field in TestOptions? + c2 = c1.WithOptions(TestOptions.DebugDll.WithOutputKind(OutputKind.WindowsApplication)); Assert.False(c1.ReferenceManagerEquals(c2)); c2 = c1.WithOptions(TestOptions.DebugModule.WithAllowUnsafe(true)); diff --git a/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs b/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs index 8b983cb9288fb..4401a222c1a55 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Immutable; using System.Reflection; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; @@ -37,8 +38,6 @@ public Exception LoadAnalyzer(string analyzerPath) public class AnalyzerFileReferenceAppDomainTests : TestBase { - private const int MaxWarningLevel = 9999; - [Fact] public void TestAnalyzerLoading_AppDomain() { @@ -99,7 +98,7 @@ public class TestAnalyzer : DiagnosticAnalyzer MetadataReference.CreateFromFile(immutable.Path), MetadataReference.CreateFromFile(analyzer.Path) }, - new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: MaxWarningLevel)); + new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: Diagnostic.MaxWarningLevel)); var analyzerFile = dir.CreateFile("MyAnalyzer.dll").WriteAllBytes(analyzerCompilation.EmitToArray()); @@ -120,8 +119,7 @@ public class TestAnalyzer : DiagnosticAnalyzer private static Assembly OnResolve(object sender, ResolveEventArgs e) { Console.WriteLine($"Resolve in {AppDomain.CurrentDomain.Id} for {e.Name}"); - return null; // Question: How nullable is enabled, and return type is `Assembly` not `Assembly?` without any CI build errors? - // I see there are no references to this method, should it be safely deleted? + return null; } } } diff --git a/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs b/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs index a58a1bda63cd1..43687b1709dbe 100644 --- a/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs @@ -3,6 +3,7 @@ // See the LICENSE file in the project root for more information. using System; +using Microsoft.CodeAnalysis; using Roslyn.Test.Utilities; using Xunit; @@ -10,8 +11,6 @@ namespace Microsoft.CodeAnalysis.UnitTests { public class CorLibTypesAndConstantTests : TestBase { - private const int MaxWarningLevel = 9999; - [Fact] public void IntegrityTest() { @@ -64,7 +63,7 @@ public void SpecialTypeIsValueType() { var comp = CSharp.CSharpCompilation.Create( "c", - options: new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: MaxWarningLevel), + options: new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: Diagnostic.MaxWarningLevel), references: new[] { TestMetadata.NetCoreApp31.SystemRuntime }); for (var specialType = SpecialType.None + 1; specialType <= SpecialType.Count; specialType++) diff --git a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs index 9b2cfe32335d8..a42f46fa72b69 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Immutable; using System.Threading; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Diagnostics; using Roslyn.Test.Utilities; @@ -18,8 +19,7 @@ namespace Microsoft.CodeAnalysis.UnitTests.Diagnostics public class CompilationWithAnalyzersTests : TestBase { - private const int MaxWarningLevel = 9999; - private static readonly CSharpCompilationOptions s_dllWithMaxWarningLevel = new(OutputKind.DynamicallyLinkedLibrary, warningLevel: MaxWarningLevel); + private static readonly CSharpCompilationOptions s_dllWithMaxWarningLevel = new(OutputKind.DynamicallyLinkedLibrary, warningLevel: Diagnostic.MaxWarningLevel); [Fact] public void GetEffectiveDiagnostics_Errors() diff --git a/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs b/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs index 1b680d785823e..f18f9a73abe1d 100644 --- a/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs @@ -4,6 +4,7 @@ using System.Collections.Immutable; using System.IO; +using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Test.Utilities; @@ -14,8 +15,7 @@ namespace Microsoft.CodeAnalysis.UnitTests { public sealed class ShadowCopyAnalyzerAssemblyLoaderTests : TestBase { - private const int MaxWarningLevel = 9999; - private static readonly CSharpCompilationOptions s_dllWithMaxWarningLevel = new(OutputKind.DynamicallyLinkedLibrary, warningLevel: MaxWarningLevel); + private static readonly CSharpCompilationOptions s_dllWithMaxWarningLevel = new(OutputKind.DynamicallyLinkedLibrary, warningLevel: Diagnostic.MaxWarningLevel); [Fact, WorkItem(32226, "https://github.com/dotnet/roslyn/issues/32226")] public void LoadWithDependency() diff --git a/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs b/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs index 06473d3134149..303f903830720 100644 --- a/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs +++ b/src/Compilers/Core/Portable/Diagnostic/Diagnostic.cs @@ -28,6 +28,11 @@ public abstract partial class Diagnostic : IEquatable, IFormattable /// internal const int DefaultWarningLevel = 4; + /// + /// The maximum warning level represented by a large value of 9999. + /// + internal const int MaxWarningLevel = 9999; + /// /// Creates a instance. /// From ef5af4b4e89ae2e6a1dd087dc3a3b1985c8c90fc Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 26 Aug 2020 14:33:37 +0000 Subject: [PATCH 18/39] More fixes --- .../Test/CommandLine/CommandLineTests.cs | 3 +- .../Attributes/AttributeTests_Synthesized.cs | 74 +++++++++---------- .../InternalsVisibleToAndStrongNameTests.cs | 2 + .../Test/Emit/Emit/CompilationEmitTests.cs | 2 +- .../Symbol/Compilation/CompilationAPITests.cs | 2 +- .../Test/WinRT/Metadata/WinMdEventTests.cs | 10 +-- .../AnalyzerFileReferenceAppDomainTests.cs | 3 +- .../Core/CodeAnalysisTest/CorLibTypesTests.cs | 3 +- .../CompilationWithAnalyzersTests.cs | 3 +- .../ShadowCopyAnalyzerAssemblyLoaderTests.cs | 3 +- .../AnalyzerConsistencyCheckerTests.cs | 4 +- .../Test/Utilities/CSharp/TestOptions.cs | 13 +++- 12 files changed, 59 insertions(+), 63 deletions(-) diff --git a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs index fbf90fdc6294d..a3895e32b279e 100644 --- a/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs +++ b/src/Compilers/CSharp/Test/CommandLine/CommandLineTests.cs @@ -2481,8 +2481,7 @@ public void Optimize() { var parsedArgs = DefaultParse(new[] { "a.cs" }, WorkingDirectory); parsedArgs.Errors.Verify(); - // TODO: I think the test is more clear with the old approach (explicitly creating CSharpCompilationOptions). What do you think? - Assert.Equal(TestOptions.DebugExe.OptimizationLevel, parsedArgs.CompilationOptions.OptimizationLevel); + Assert.Equal(new CSharpCompilationOptions(OutputKind.ConsoleApplication).OptimizationLevel, parsedArgs.CompilationOptions.OptimizationLevel); parsedArgs = DefaultParse(new[] { "/optimize-", "a.cs" }, WorkingDirectory); parsedArgs.Errors.Verify(); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs index b73851939fb79..46da13633f614 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs @@ -166,7 +166,7 @@ class Test public event Func MyEvent; } "; - var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(source, options: options, symbolValidator: module => @@ -215,7 +215,7 @@ abstract class C public event Func E; } "; - var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(source, options: options, symbolValidator: module => @@ -254,7 +254,7 @@ void Goo() } } "; - var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilation(source, options: options), symbolValidator: m => @@ -282,7 +282,7 @@ void Goo() } } "; - var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilation(source, options: options), symbolValidator: m => @@ -420,7 +420,7 @@ public IEnumerable Iterator() } } "; - var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilation(source, options: options), symbolValidator: module => @@ -475,7 +475,7 @@ public async Task Goo() } } "; - var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -533,7 +533,7 @@ public override async Task GetIntAsync() } } "; - var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -571,7 +571,7 @@ public override async Task GetIntAsync(int x) } } "; - var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -614,7 +614,7 @@ public override async Task GetAsync<[Attr] T>([Attr] T t) } } "; - var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -664,7 +664,7 @@ public static void Main() { } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -699,7 +699,7 @@ public static void Main() { } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -734,7 +734,7 @@ public static void Main() { } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -769,7 +769,7 @@ public static void Main() { } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -805,7 +805,7 @@ public static void Main() { } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { VerifyDebuggableAttribute(module.GetAttributes().Single(), optimizationLevel, isSynthesized: false); @@ -843,7 +843,7 @@ public static void Main() { } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -878,7 +878,7 @@ public static void Main() { } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { VerifyCompilationRelaxationsAttribute(module.GetAttributes().Single(), isSynthesized: false); @@ -915,7 +915,7 @@ public static void Main() { } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); CompileAndVerify(source, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { VerifyDebuggableAttribute(module.GetAttributes().Single(), options.OptimizationLevel, isSynthesized: false); @@ -941,7 +941,7 @@ public static void Main() [MemberData(nameof(FullMatrixTheoryData))] public void MissingWellKnownAttributesNoDiagnosticsAndNoSynthesizedAttributes(OutputKind outputKind, OptimizationLevel optimizationLevel) { - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); var compilation = CreateEmptyCompilation("", options: options); if (outputKind.IsApplication()) @@ -979,7 +979,7 @@ public static void Main() } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); var compilation = CreateCompilation(code, options: options); CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => @@ -1028,7 +1028,7 @@ public static void Main() } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); var compilation = CreateCompilation(code, options: options); CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => @@ -1075,7 +1075,7 @@ public static void Main() } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); var compilation = CreateCompilation(code, options: options); CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => @@ -1119,7 +1119,7 @@ public static void Main() } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); var compilation = CreateCompilation(code, options: options); CompileAndVerify(compilation, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => @@ -1162,7 +1162,7 @@ public static void Main() { } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); var compilation = CreateCompilation(source, options: options); if (outputKind.IsNetModule()) @@ -1193,7 +1193,7 @@ public void AppliedCompilationRelaxationsOnModuleSupressesAssemblyAttributes(Out using System.Runtime.CompilerServices; [assembly: CompilationRelaxationsAttribute(0)] -", options: TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel)); +", options: TestOptions.CreateTestOptions(outputKind, optimizationLevel)); var reference = ModuleMetadata.CreateFromImage(referenceComp.EmitToArray()).GetReference(); @@ -1206,7 +1206,7 @@ public static void Main() } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); CompileAndVerify(source, references: new[] { reference }, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -1234,7 +1234,7 @@ public void AppliedRuntimeCompatibilityOnModuleSupressesAssemblyAttributes(Outpu using System.Runtime.CompilerServices; [assembly: RuntimeCompatibilityAttribute()] -", options: TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel)); +", options: TestOptions.CreateTestOptions(outputKind, optimizationLevel)); var reference = ModuleMetadata.CreateFromImage(referenceComp.EmitToArray()).GetReference(); @@ -1247,7 +1247,7 @@ public static void Main() } }"; - var options = TestOptions.DebugDll.WithOutputKind(outputKind).WithOptimizationLevel(optimizationLevel); + var options = TestOptions.CreateTestOptions(outputKind, optimizationLevel); CompileAndVerify(source, references: new[] { reference }, options: options, verify: outputKind.IsNetModule() ? Verification.Skipped : Verification.Passes, symbolValidator: module => { var attributes = module.ContainingAssembly.GetAttributes(); @@ -1282,7 +1282,7 @@ public static void Main() } }"; - var compilation = CreateCompilationWithMscorlib40(source, options: TestOptions.UnsafeReleaseDll.WithOutputKind(outputKind)); + var compilation = CreateCompilationWithMscorlib40(source, options: TestOptions.CreateTestOptions(outputKind, OptimizationLevel.Release, allowUnsafe: true)); //Skipped because PeVerify fails to run with "The module was expected to contain an assembly manifest." CompileAndVerify(compilation, verify: Verification.Skipped, symbolValidator: module => @@ -1345,8 +1345,7 @@ public static async void F() } }"; - var options = TestOptions.DebugDll - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -1389,8 +1388,7 @@ public static void F() } }"; - var options = TestOptions.DebugDll - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -1432,8 +1430,7 @@ public class Test } }"; - var options = TestOptions.DebugDll - .WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -1475,8 +1472,7 @@ public static async void F() } }"; - var referenceOptions = TestOptions.DebugDll - .WithOptimizationLevel(optimizationLevel) + var referenceOptions = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); var reference = CreateCompilationWithMscorlib45(source, options: referenceOptions).EmitToImageReference(options: new EmitOptions(metadataOnly: true)); @@ -1515,7 +1511,7 @@ public static IEnumerable F() } }"; - var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -1545,7 +1541,7 @@ public class Test } }"; - var options = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var options = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); CompileAndVerify(CreateCompilationWithMscorlib45(source, options: options), symbolValidator: module => @@ -1575,7 +1571,7 @@ public class Test } }"; - var referenceOptions = TestOptions.DebugDll.WithOptimizationLevel(optimizationLevel) + var referenceOptions = TestOptions.CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, optimizationLevel) .WithMetadataImportOptions(MetadataImportOptions.All); var reference = CreateCompilationWithMscorlib45(source, options: referenceOptions).EmitToImageReference(options: new EmitOptions(metadataOnly: true)); diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs index 39863116dacc0..d5dc002fc29bc 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/InternalsVisibleToAndStrongNameTests.cs @@ -2624,6 +2624,7 @@ public void Bug1095618(CSharpParseOptions parseOptions) public void ConsistentErrorMessageWhenProvidingNullKeyFile(CSharpParseOptions parseOptions) { var options = TestOptions.DebugDll; + Assert.Null(options.CryptoKeyFile); var compilation = CreateCompilation(string.Empty, options: options, parseOptions: parseOptions).VerifyDiagnostics(); VerifySignedBitSetAfterEmit(compilation, expectedToBeSigned: false); @@ -2646,6 +2647,7 @@ public void ConsistentErrorMessageWhenProvidingEmptyKeyFile(CSharpParseOptions p public void ConsistentErrorMessageWhenProvidingNullKeyFile_PublicSign(CSharpParseOptions parseOptions) { var options = TestOptions.DebugDll.WithPublicSign(true); + Assert.Null(options.CryptoKeyFile); CreateCompilation(string.Empty, options: options, parseOptions: parseOptions).VerifyDiagnostics( // error CS8102: Public signing was specified and requires a public key, but no public key was specified. Diagnostic(ErrorCode.ERR_PublicSignButNoKey).WithLocation(1, 1)); diff --git a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs index dc8dd79782b4e..6d6f1fb10eb20 100644 --- a/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs +++ b/src/Compilers/CSharp/Test/Emit/Emit/CompilationEmitTests.cs @@ -3426,7 +3426,7 @@ public static void Main() { } }"; - var compilation = CreateCompilation(source, options: TestOptions.DebugWindowsRuntimeApp); + var compilation = CreateCompilation(source, options: TestOptions.CreateTestOptions(OutputKind.WindowsRuntimeApplication, OptimizationLevel.Debug)); var peHeaders = new PEHeaders(compilation.EmitToStream()); //interesting COFF bits diff --git a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs index 8c25f520da8f8..4dcbf9e163218 100644 --- a/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Compilation/CompilationAPITests.cs @@ -1977,7 +1977,7 @@ public void ReferenceManagerReuse_WithOptions() c2 = c1.WithOptions(TestOptions.ReleaseDll); Assert.False(c1.ReferenceManagerEquals(c2)); - c2 = c1.WithOptions(TestOptions.DebugDll.WithOutputKind(OutputKind.WindowsApplication)); + c2 = c1.WithOptions(TestOptions.CreateTestOptions(OutputKind.WindowsApplication, OptimizationLevel.Debug)); Assert.False(c1.ReferenceManagerEquals(c2)); c2 = c1.WithOptions(TestOptions.DebugModule.WithAllowUnsafe(true)); diff --git a/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs b/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs index 7b4031d23c7b9..e97172389d632 100644 --- a/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs +++ b/src/Compilers/CSharp/Test/WinRT/Metadata/WinMdEventTests.cs @@ -2909,7 +2909,7 @@ interface I foreach (OutputKind kind in Enum.GetValues(typeof(OutputKind))) { - var comp = CreateEmptyCompilation(source, WinRtRefs, TestOptions.DebugDll.WithOutputKind(kind)); + var comp = CreateEmptyCompilation(source, WinRtRefs, TestOptions.CreateTestOptions(kind, OptimizationLevel.Debug)); comp.VerifyDiagnostics(); var @class = comp.GlobalNamespace.GetMember("C"); @@ -2953,7 +2953,7 @@ public event System.Action WinRT foreach (OutputKind kind in new[] { OutputKind.DynamicallyLinkedLibrary, OutputKind.WindowsRuntimeMetadata }) { - var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { ilRef }), TestOptions.DebugDll.WithOutputKind(kind)); + var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { ilRef }), TestOptions.CreateTestOptions(kind, OptimizationLevel.Debug)); comp.VerifyDiagnostics(); var @class = comp.GlobalNamespace.GetMember("C"); @@ -3022,7 +3022,7 @@ public override event System.Action WinRT foreach (OutputKind kind in new[] { OutputKind.DynamicallyLinkedLibrary, OutputKind.WindowsRuntimeMetadata }) { - var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { interfaceILRef, baseILRef }), TestOptions.DebugDll.WithOutputKind(kind)); + var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { interfaceILRef, baseILRef }), TestOptions.CreateTestOptions(kind, OptimizationLevel.Debug)); comp.VerifyDiagnostics( // (40,41): error CS1991: 'OverrideAndImplIncorrectly.WinRT' cannot implement 'Interface.WinRT' because 'Interface.WinRT' is a Windows Runtime event and 'OverrideAndImplIncorrectly.WinRT' is a regular .NET event. // public override event System.Action WinRT @@ -3088,7 +3088,7 @@ event System.Action Interface.WinRT foreach (OutputKind kind in new[] { OutputKind.DynamicallyLinkedLibrary, OutputKind.WindowsRuntimeMetadata }) { - var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { ilRef }), TestOptions.DebugDll.WithOutputKind(kind)); + var comp = CreateEmptyCompilation(source, WinRtRefs.Concat(new[] { ilRef }), TestOptions.CreateTestOptions(kind, OptimizationLevel.Debug)); comp.VerifyDiagnostics(); var @class = comp.GlobalNamespace.GetMember("C"); @@ -3283,7 +3283,7 @@ static void Main() { } foreach (OutputKind kind in new[] { OutputKind.DynamicallyLinkedLibrary, OutputKind.WindowsRuntimeMetadata }) { - var comp = CreateEmptyCompilation(source, WinRtRefs, TestOptions.DebugDll.WithOutputKind(kind)); + var comp = CreateEmptyCompilation(source, WinRtRefs, TestOptions.CreateTestOptions(kind, OptimizationLevel.Debug)); comp.VerifyDiagnostics( // (10,25): warning CS0067: The event 'C.F' is never used // event System.Action F; diff --git a/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs b/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs index 4401a222c1a55..53595fd9c1493 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Analyzers/AnalyzerFileReferenceAppDomainTests.cs @@ -9,7 +9,6 @@ using System; using System.Collections.Immutable; using System.Reflection; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; @@ -98,7 +97,7 @@ public class TestAnalyzer : DiagnosticAnalyzer MetadataReference.CreateFromFile(immutable.Path), MetadataReference.CreateFromFile(analyzer.Path) }, - new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: Diagnostic.MaxWarningLevel)); + new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: CodeAnalysis.Diagnostic.MaxWarningLevel)); var analyzerFile = dir.CreateFile("MyAnalyzer.dll").WriteAllBytes(analyzerCompilation.EmitToArray()); diff --git a/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs b/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs index 43687b1709dbe..b3d9bd72c5f83 100644 --- a/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/CorLibTypesTests.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information. using System; -using Microsoft.CodeAnalysis; using Roslyn.Test.Utilities; using Xunit; @@ -63,7 +62,7 @@ public void SpecialTypeIsValueType() { var comp = CSharp.CSharpCompilation.Create( "c", - options: new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: Diagnostic.MaxWarningLevel), + options: new CSharp.CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: CodeAnalysis.Diagnostic.MaxWarningLevel), references: new[] { TestMetadata.NetCoreApp31.SystemRuntime }); for (var specialType = SpecialType.None + 1; specialType <= SpecialType.Count; specialType++) diff --git a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs index a42f46fa72b69..3e03f5162b7c7 100644 --- a/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/Diagnostics/CompilationWithAnalyzersTests.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Immutable; using System.Threading; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Diagnostics; using Roslyn.Test.Utilities; @@ -19,7 +18,7 @@ namespace Microsoft.CodeAnalysis.UnitTests.Diagnostics public class CompilationWithAnalyzersTests : TestBase { - private static readonly CSharpCompilationOptions s_dllWithMaxWarningLevel = new(OutputKind.DynamicallyLinkedLibrary, warningLevel: Diagnostic.MaxWarningLevel); + private static readonly CSharpCompilationOptions s_dllWithMaxWarningLevel = new(OutputKind.DynamicallyLinkedLibrary, warningLevel: CodeAnalysis.Diagnostic.MaxWarningLevel); [Fact] public void GetEffectiveDiagnostics_Errors() diff --git a/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs b/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs index f18f9a73abe1d..987a64b67d289 100644 --- a/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs +++ b/src/Compilers/Core/CodeAnalysisTest/ShadowCopyAnalyzerAssemblyLoaderTests.cs @@ -4,7 +4,6 @@ using System.Collections.Immutable; using System.IO; -using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Test.Utilities; @@ -15,7 +14,7 @@ namespace Microsoft.CodeAnalysis.UnitTests { public sealed class ShadowCopyAnalyzerAssemblyLoaderTests : TestBase { - private static readonly CSharpCompilationOptions s_dllWithMaxWarningLevel = new(OutputKind.DynamicallyLinkedLibrary, warningLevel: Diagnostic.MaxWarningLevel); + private static readonly CSharpCompilationOptions s_dllWithMaxWarningLevel = new(OutputKind.DynamicallyLinkedLibrary, warningLevel: CodeAnalysis.Diagnostic.MaxWarningLevel); [Fact, WorkItem(32226, "https://github.com/dotnet/roslyn/issues/32226")] public void LoadWithDependency() diff --git a/src/Compilers/Server/VBCSCompilerTests/AnalyzerConsistencyCheckerTests.cs b/src/Compilers/Server/VBCSCompilerTests/AnalyzerConsistencyCheckerTests.cs index 1ba1159e6dd0a..d50e7b24116a2 100644 --- a/src/Compilers/Server/VBCSCompilerTests/AnalyzerConsistencyCheckerTests.cs +++ b/src/Compilers/Server/VBCSCompilerTests/AnalyzerConsistencyCheckerTests.cs @@ -18,8 +18,6 @@ namespace Microsoft.CodeAnalysis.CompilerServer.UnitTests { public class AnalyzerConsistencyCheckerTests : TestBase { - private const int MaxWarningLevel = 9999; - [Fact] public void MissingReference() { @@ -100,7 +98,7 @@ public void NetstandardIgnored() name, new[] { SyntaxFactory.ParseSyntaxTree(@"class C {}") }, references: new MetadataReference[] { MetadataReference.CreateFromImage(TestMetadata.ResourcesNetStandard20.netstandard) }, - options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: MaxWarningLevel)); + options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, warningLevel: Diagnostic.MaxWarningLevel)); var compFile = directory.CreateFile(name); comp.Emit(compFile.Path); diff --git a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs index dfa7bedbcb555..283ee22803ddc 100644 --- a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs +++ b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs @@ -7,15 +7,12 @@ using System.Collections.Immutable; using System.Linq; using Roslyn.Test.Utilities; -using Microsoft.CodeAnalysis.Diagnostics; using Microsoft.CodeAnalysis.Emit; namespace Microsoft.CodeAnalysis.CSharp.Test.Utilities { public static class TestOptions { - private const int MaxWarningLevel = 9999; - public static readonly CSharpParseOptions Regular = new CSharpParseOptions(kind: SourceCodeKind.Regular, documentationMode: DocumentationMode.Parse); public static readonly CSharpParseOptions Script = Regular.WithKind(SourceCodeKind.Script); public static readonly CSharpParseOptions Regular6 = Regular.WithLanguageVersion(LanguageVersion.CSharp6); @@ -145,7 +142,15 @@ public static CSharpCompilationOptions WithSpecificDiagnosticOptions(this CSharp return options.WithSpecificDiagnosticOptions(ImmutableDictionary.Empty.Add(key1, value).Add(key2, value)); } - private static CSharpCompilationOptions CreateTestOptions(OutputKind outputKind, OptimizationLevel optimizationLevel) => new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel, warningLevel: MaxWarningLevel); + /// + /// Create with the maximum warning level. + /// + /// The output kind of the created compilation options. + /// The optimization level of the created compilation options. + /// A boolean specifying whether to allow unsafe code. Defaults to false. + /// A CSharpCompilationOptions with the specified , , and . + internal static CSharpCompilationOptions CreateTestOptions(OutputKind outputKind, OptimizationLevel optimizationLevel, bool allowUnsafe = false) + => new CSharpCompilationOptions(outputKind, optimizationLevel: optimizationLevel, warningLevel: Diagnostic.MaxWarningLevel, allowUnsafe: allowUnsafe); } } From 4a422d8b675c977d3ec424104c407329196211d6 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Wed, 26 Aug 2020 14:43:13 +0000 Subject: [PATCH 19/39] Remove field --- src/Compilers/Test/Utilities/CSharp/TestOptions.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs index 283ee22803ddc..fa9440a1c16a5 100644 --- a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs +++ b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs @@ -55,7 +55,6 @@ public static class TestOptions public static readonly CSharpCompilationOptions DebugDll = CreateTestOptions(OutputKind.DynamicallyLinkedLibrary, OptimizationLevel.Debug); public static readonly CSharpCompilationOptions DebugExe = CreateTestOptions(OutputKind.ConsoleApplication, OptimizationLevel.Debug); - public static readonly CSharpCompilationOptions DebugWindowsRuntimeApp = CreateTestOptions(OutputKind.WindowsRuntimeApplication, OptimizationLevel.Debug); public static readonly CSharpCompilationOptions ReleaseWinMD = CreateTestOptions(OutputKind.WindowsRuntimeMetadata, OptimizationLevel.Release); public static readonly CSharpCompilationOptions DebugWinMD = CreateTestOptions(OutputKind.WindowsRuntimeMetadata, OptimizationLevel.Debug); From 248daa8f6a0d66dc818abc1aadf1cba4cb3de4a4 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Fri, 28 Aug 2020 10:28:59 +0000 Subject: [PATCH 20/39] Fix WarningVersionTests by explicitly using DefaultWarningLevel when needed --- .../Semantic/Semantics/WarningVersionTests.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/WarningVersionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/WarningVersionTests.cs index 4c8d3a86398f7..cfc59d1d2081a 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/WarningVersionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/WarningVersionTests.cs @@ -43,7 +43,7 @@ struct S // if (s != null) { } Diagnostic(ErrorCode.WRN_NubExprIsConstBool2, "s != null").WithArguments("true", "S", "S?").WithLocation(7, 13) }; - CreateCompilation(source).VerifyDiagnostics(); + CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics(); CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningLevel(3)).VerifyDiagnostics(); CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningLevel(4)).VerifyDiagnostics(); CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics(whenWave5); @@ -73,7 +73,7 @@ static class SC { } // _ = o as SC; Diagnostic(ErrorCode.WRN_StaticInAsOrIs, "o as SC").WithArguments("SC").WithLocation(7, 17) }; - CreateCompilation(source).VerifyDiagnostics(); + CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics(); CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningLevel(4)).VerifyDiagnostics(); CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics(whenWave5); } @@ -112,7 +112,7 @@ static void M2() // var i = ()=>{} + x; Diagnostic(ErrorCode.WRN_PrecedenceInversion, "+").WithArguments("+").WithLocation(20, 24) }; - CreateCompilation(source).VerifyDiagnostics(); + CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics(); CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningLevel(4)).VerifyDiagnostics(); CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics(whenWave5); } @@ -137,7 +137,7 @@ public Program(int dummy) { } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (4,12): warning CS8822: Auto-implemented property 'Program.Property' must be fully assigned before control is returned to the caller. @@ -166,7 +166,7 @@ public Program(int dummy) { } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (4,12): warning CS8823: Field 'Program.Field' must be fully assigned before control is returned to the caller @@ -194,7 +194,7 @@ void M(out Struct param) { } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (3,10): warning CS8824: The out parameter 'param' must be assigned to before control leaves the current method @@ -225,7 +225,7 @@ public struct Struct Property = default; } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (6,21): warning CS8825: Use of possibly unassigned auto-implemented property 'Property' @@ -256,7 +256,7 @@ public struct Struct Field = default; } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (6,21): warning CS8826: Use of possibly unassigned field 'Field' @@ -287,7 +287,7 @@ public struct Struct this.Field = default; } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (6,22): warning CS8827: The 'this' object cannot be used before all of its fields have been assigned @@ -317,7 +317,7 @@ public static void M(out Struct r1) r1 = default; } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (5,18): warning CS8828: Use of unassigned out parameter 'r1' @@ -347,7 +347,7 @@ public static void Main() var r2 = r1; } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (6,18): warning CS8829: Use of unassigned local variable 'r1' From 99783b062d80975fb1561f14e01ae1d13e95f023 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Fri, 28 Aug 2020 10:57:32 +0000 Subject: [PATCH 21/39] Fix Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests + One TODO --- .../Test/Semantic/FlowAnalysis/StructTests.cs | 14 +++++++------- .../CSharp/Test/Semantic/Semantics/DynamicTests.cs | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/StructTests.cs b/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/StructTests.cs index 433b8145f2bf4..63330a48bf08c 100644 --- a/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/StructTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/FlowAnalysis/StructTests.cs @@ -265,14 +265,14 @@ public static void Main() Diagnostic(ErrorCode.ERR_UseDefViolation, "v1").WithArguments("v1").WithLocation(9, 18) ); CreateCompilation(source2, - options: TestOptions.ReleaseDll, + options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel), references: new MetadataReference[] { sourceReference }).VerifyDiagnostics( // (9,18): error CS0165: Use of unassigned local variable 'v1' // var v2 = v1; Diagnostic(ErrorCode.ERR_UseDefViolation, "v1").WithArguments("v1").WithLocation(9, 18) ); CreateCompilation(source2, - options: TestOptions.ReleaseDll, + options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel), references: new MetadataReference[] { metadataReference }).VerifyDiagnostics( // (9,18): error CS0165: Use of unassigned local variable 'v1' // var v2 = v1; @@ -334,9 +334,9 @@ public static void Main() var r2 = r1; } }"; - CreateCompilation(source2, references: new MetadataReference[] { sourceReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { sourceReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); - CreateCompilation(source2, references: new MetadataReference[] { metadataReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { metadataReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); CreateCompilation(source2, references: new MetadataReference[] { sourceReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (6,18): warning CS8829: Use of unassigned local variable 'r1' @@ -379,9 +379,9 @@ public static void Main() var r2 = r1; } }"; - CreateCompilation(source2, references: new MetadataReference[] { sourceReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { sourceReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); - CreateCompilation(source2, references: new MetadataReference[] { metadataReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { metadataReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); CreateCompilation(source2, references: new MetadataReference[] { sourceReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (6,18): warning CS8829: Use of unassigned local variable 'r1' @@ -499,7 +499,7 @@ public static void Main() var r2 = r1; } }"; - CreateCompilation(source2, references: new MetadataReference[] { moduleReference }).VerifyDiagnostics( + CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(CodeAnalysis.Diagnostic.DefaultWarningLevel)).VerifyDiagnostics( ); CreateCompilation(source2, references: new MetadataReference[] { moduleReference }, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (6,18): warning CS8829: Use of unassigned local variable 'r1' diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs index 2becb444180a7..7e7b364b3ffa6 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs @@ -795,7 +795,7 @@ static unsafe void M(dynamic d1, System.TypedReference tr) d1 + M, ( ()=>{} ) - d1, d1 >> ( ()=>{} ), - delegate {} << d1, + delegate {} << d1, // TODO: This is failing due to new warning ""WRN_PrecedenceInversion"". Unclear to me what I should do here. d1 << delegate {}, (int*)null > d1, d1 < (int*)null, From a94ec22dfdb990f2fa44c81b544eb3c502fe1191 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Fri, 28 Aug 2020 11:00:31 +0000 Subject: [PATCH 22/39] TODO in NameCollisionTests.TestCollisionInsideFor2 --- .../CSharp/Test/Semantic/Semantics/NameCollisionTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NameCollisionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NameCollisionTests.cs index 5f107bfa527e1..c6f13efa5504e 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NameCollisionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NameCollisionTests.cs @@ -1259,7 +1259,7 @@ private string Property { get { - for (var name = from name in ""string"" orderby name select name; name != null; ) ; // 1931 + for (var name = from name in ""string"" orderby name select name; name != null; ) ; // 1931 TODO: There is an extra WRN_PrecedenceInversion for (IEnumerable name = null; name == from name in ""string"" orderby name select name; ) ; // 1931 for (IEnumerable name = null; name == null; name = from name in ""string"" orderby name select name ) ; // 1931 return string.Empty; From d469c4f700d65193c0c9dacd770db6fdbe6c5e76 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Fri, 4 Sep 2020 21:26:55 +0000 Subject: [PATCH 23/39] Fix a few more tests --- .../CodeGen/CodeGenOptimizedNullableOperators.cs | 4 ++-- .../CSharp/Test/Semantic/Semantics/DynamicTests.cs | 2 +- .../Semantic/Semantics/PatternMatchingTests.cs | 4 ++-- .../Semantic/Semantics/PatternMatchingTests2.cs | 2 +- .../Test/Semantic/Semantics/SemanticErrorTests.cs | 14 +++++++------- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOptimizedNullableOperators.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOptimizedNullableOperators.cs index 8a5b4d30a8257..aeca4de5c8c06 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOptimizedNullableOperators.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenOptimizedNullableOperators.cs @@ -1095,7 +1095,7 @@ .maxstack 1 }"; string expectedIL6 = expectedIL4; - CompileAndVerify(source, expectedOutput: expectedOutput).VerifyDiagnostics( + CompileAndVerify(source, expectedOutput: expectedOutput, options: TestOptions.ReleaseExe.WithWarningLevel(4)).VerifyDiagnostics( // (21,16): warning CS0472: The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'short?' // return new int?(N1()) == new short?(); Diagnostic(ErrorCode.WRN_NubExprIsConstBool, "new int?(N1()) == new short?()").WithArguments("false", "int", "short?").WithLocation(21, 16), @@ -1109,7 +1109,7 @@ .maxstack 1 // return ((S?)null) < new S?(N4()); Diagnostic(ErrorCode.WRN_CmpAlwaysFalse, "((S?)null) < new S?(N4())").WithArguments("S?").WithLocation(41, 16) ); - var comp = CompileAndVerify(source, expectedOutput: expectedOutput, options: TestOptions.ReleaseExe.WithWarningLevel(5)); + var comp = CompileAndVerify(source, expectedOutput: expectedOutput); comp.VerifyDiagnostics( // (21,16): warning CS0472: The result of the expression is always 'false' since a value of type 'int' is never equal to 'null' of type 'short?' // return new int?(N1()) == new short?(); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs index 7e7b364b3ffa6..d7984f3e34935 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs @@ -795,7 +795,7 @@ static unsafe void M(dynamic d1, System.TypedReference tr) d1 + M, ( ()=>{} ) - d1, d1 >> ( ()=>{} ), - delegate {} << d1, // TODO: This is failing due to new warning ""WRN_PrecedenceInversion"". Unclear to me what I should do here. + (delegate {}) << d1, d1 << delegate {}, (int*)null > d1, d1 < (int*)null, diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs index d7df50500e956..3f6307ffee23f 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs @@ -3633,11 +3633,11 @@ public static void Main() { if (null is 1) {} if (Main is 2) {} - if (delegate {} is 3) {} + if ((delegate {}) is 3) {} if ((1, null) is 4) {} if (null is var x1) {} if (Main is var x2) {} - if (delegate {} is var x3) {} + if ((delegate {}) is var x3) {} if ((1, null) is var x4) {} } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests2.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests2.cs index 543d065c908ca..c7fa7206a66d7 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests2.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests2.cs @@ -2970,7 +2970,7 @@ class C { void F(object o) { - _ = switch { this.F(1) => 1 }; + _ = switch { this.F(1) => 1 }; // TODO: This is reporting WRN_PrecedenceInversion } }"; CreateCompilation(source).VerifyDiagnostics( diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs index b05e2cdb8df98..439bf8796425d 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs @@ -275,8 +275,8 @@ static void Main(string[] args) C p = new C(); boo goo = null; goo += p.bar + far;// Invalid - goo += (x) => { System.Console.WriteLine(""Lambda:{0}"", x); } + far;// Invalid - goo += delegate (int x) { System.Console.WriteLine(""Anonymous:{0}"", x); } + far;// Invalid + goo += (x) => { System.Console.WriteLine(""Lambda:{0}"", x); } + far;// Invalid **TODO** + goo += delegate (int x) { System.Console.WriteLine(""Anonymous:{0}"", x); } + far;// Invalid **TODO** } } "; @@ -12552,9 +12552,9 @@ class Test static int Main() { bool b1 = (() => { }) is Del; // CS0837 - bool b2 = delegate() { } is Del;// CS0837 - Del d1 = () => { } as Del; // CS0837 - Del d2 = delegate() { } as Del; // CS0837 + bool b2 = (delegate() { }) is Del;// CS0837 + Del d1 = (() => { }) as Del; // CS0837 + Del d2 = (delegate() { }) as Del; // CS0837 return 1; } } @@ -20637,8 +20637,8 @@ public static void Main() Diagnostic(ErrorCode.WRN_NubExprIsConstBool, "(E?)null != 0").WithArguments("true", "MyClass.E", "MyClass.E?").WithLocation(96, 11) }; var compatibleExpected = fullExpected.Where(d => !d.Code.Equals((int)ErrorCode.WRN_NubExprIsConstBool2)).ToArray(); - this.CompileAndVerify(source: text, expectedOutput: expected).VerifyDiagnostics(compatibleExpected); - this.CompileAndVerify(source: text, expectedOutput: expected, options: TestOptions.ReleaseExe.WithWarningLevel(5)).VerifyDiagnostics(fullExpected); + this.CompileAndVerify(source: text, expectedOutput: expected, options: TestOptions.ReleaseExe.WithWarningLevel(4)).VerifyDiagnostics(compatibleExpected); + this.CompileAndVerify(source: text, expectedOutput: expected).VerifyDiagnostics(fullExpected); } [Fact] From 5ea9ff7e03481904c6b10c2984175be97e0517a6 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sat, 5 Sep 2020 22:12:57 +0200 Subject: [PATCH 24/39] Address feedback --- .../Test/Semantic/Semantics/DynamicTests.cs | 5 +++- .../Semantics/PatternMatchingTests.cs | 5 +++- .../Semantics/PatternMatchingTests2.cs | 7 +++-- .../Semantic/Semantics/SemanticErrorTests.cs | 29 ++++++++++++++----- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs index d7984f3e34935..14df0ce0b40ae 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/DynamicTests.cs @@ -795,7 +795,7 @@ static unsafe void M(dynamic d1, System.TypedReference tr) d1 + M, ( ()=>{} ) - d1, d1 >> ( ()=>{} ), - (delegate {}) << d1, + delegate {} << d1, d1 << delegate {}, (int*)null > d1, d1 < (int*)null, @@ -823,6 +823,9 @@ static void Main() {} // (14,13): error CS0019: Operator '<<' cannot be applied to operands of type 'anonymous method' and 'dynamic' // delegate {} << d1, Diagnostic(ErrorCode.ERR_BadBinaryOps, "delegate {} << d1").WithArguments("<<", "anonymous method", "dynamic").WithLocation(14, 13), + // (14,25): warning CS8848: Operator '<<' cannot be used here due to precedence. Use parentheses to disambiguate. + // delegate {} << d1, + Diagnostic(ErrorCode.WRN_PrecedenceInversion, "<<").WithArguments("<<").WithLocation(14, 25), // (15,13): error CS0019: Operator '<<' cannot be applied to operands of type 'dynamic' and 'anonymous method' // d1 << delegate {}, Diagnostic(ErrorCode.ERR_BadBinaryOps, "d1 << delegate {}").WithArguments("<<", "dynamic", "anonymous method").WithLocation(15, 13), diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs index 3f6307ffee23f..8d3f4cbceda63 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs @@ -3633,7 +3633,7 @@ public static void Main() { if (null is 1) {} if (Main is 2) {} - if ((delegate {}) is 3) {} + if (delegate {} is 3) {} if ((1, null) is 4) {} if (null is var x1) {} if (Main is var x2) {} @@ -3652,6 +3652,9 @@ public static void Main() // (8,13): error CS0837: The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group. // if (delegate {} is 3) {} Diagnostic(ErrorCode.ERR_LambdaInIsAs, "delegate {} is 3").WithLocation(8, 13), + // (8,25): warning CS8848: Operator 'is' cannot be used here due to precedence. Use parentheses to disambiguate. + // if (delegate {} is 3) {} + Diagnostic(ErrorCode.WRN_PrecedenceInversion, "is").WithArguments("is").WithLocation(8, 25), // (9,13): error CS0023: Operator 'is' cannot be applied to operand of type '(int, )' // if ((1, null) is 4) {} Diagnostic(ErrorCode.ERR_BadUnaryOp, "(1, null) is 4").WithArguments("is", "(int, )").WithLocation(9, 13), diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests2.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests2.cs index c7fa7206a66d7..df52fc7748f45 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests2.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests2.cs @@ -2970,13 +2970,16 @@ class C { void F(object o) { - _ = switch { this.F(1) => 1 }; // TODO: This is reporting WRN_PrecedenceInversion + _ = switch { this.F(1) => 1 }; } }"; CreateCompilation(source).VerifyDiagnostics( // (6,13): error CS1525: Invalid expression term 'switch' // _ = switch { this.F(1) => 1 }; - Diagnostic(ErrorCode.ERR_InvalidExprTerm, "switch").WithArguments("switch").WithLocation(6, 13) + Diagnostic(ErrorCode.ERR_InvalidExprTerm, "switch").WithArguments("switch").WithLocation(6, 13), + // (6,13): warning CS8848: Operator 'switch' cannot be used here due to precedence. Use parentheses to disambiguate. + // _ = switch { this.F(1) => 1 }; + Diagnostic(ErrorCode.WRN_PrecedenceInversion, "switch").WithArguments("switch").WithLocation(6, 13) ); } } diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs index 439bf8796425d..27616ebb7af13 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/SemanticErrorTests.cs @@ -275,8 +275,8 @@ static void Main(string[] args) C p = new C(); boo goo = null; goo += p.bar + far;// Invalid - goo += (x) => { System.Console.WriteLine(""Lambda:{0}"", x); } + far;// Invalid **TODO** - goo += delegate (int x) { System.Console.WriteLine(""Anonymous:{0}"", x); } + far;// Invalid **TODO** + goo += (x) => { System.Console.WriteLine(""Lambda:{0}"", x); } + far;// Invalid + goo += delegate (int x) { System.Console.WriteLine(""Anonymous:{0}"", x); } + far;// Invalid } } "; @@ -287,9 +287,15 @@ static void Main(string[] args) // (12,16): error CS0019: Operator '+' cannot be applied to operands of type 'lambda expression' and 'method group' // goo += (x) => { System.Console.WriteLine("Lambda:{0}", x); } + far;// Invalid Diagnostic(ErrorCode.ERR_BadBinaryOps, @"(x) => { System.Console.WriteLine(""Lambda:{0}"", x); } + far").WithArguments("+", "lambda expression", "method group").WithLocation(12, 16), + // (12,70): warning CS8848: Operator '+' cannot be used here due to precedence. Use parentheses to disambiguate. + // goo += (x) => { System.Console.WriteLine("Lambda:{0}", x); } + far;// Invalid + Diagnostic(ErrorCode.WRN_PrecedenceInversion, "+").WithArguments("+").WithLocation(12, 70), // (13,16): error CS0019: Operator '+' cannot be applied to operands of type 'anonymous method' and 'method group' // goo += delegate (int x) { System.Console.WriteLine("Anonymous:{0}", x); } + far;// Invalid - Diagnostic(ErrorCode.ERR_BadBinaryOps, @"delegate (int x) { System.Console.WriteLine(""Anonymous:{0}"", x); } + far").WithArguments("+", "anonymous method", "method group").WithLocation(13, 16) + Diagnostic(ErrorCode.ERR_BadBinaryOps, @"delegate (int x) { System.Console.WriteLine(""Anonymous:{0}"", x); } + far").WithArguments("+", "anonymous method", "method group").WithLocation(13, 16), + // (13,83): warning CS8848: Operator '+' cannot be used here due to precedence. Use parentheses to disambiguate. + // goo += delegate (int x) { System.Console.WriteLine("Anonymous:{0}", x); } + far;// Invalid + Diagnostic(ErrorCode.WRN_PrecedenceInversion, "+").WithArguments("+").WithLocation(13, 83) ); } @@ -12552,9 +12558,9 @@ class Test static int Main() { bool b1 = (() => { }) is Del; // CS0837 - bool b2 = (delegate() { }) is Del;// CS0837 - Del d1 = (() => { }) as Del; // CS0837 - Del d2 = (delegate() { }) as Del; // CS0837 + bool b2 = delegate() { } is Del;// CS0837 + Del d1 = () => { } as Del; // CS0837 + Del d2 = delegate() { } as Del; // CS0837 return 1; } } @@ -12567,12 +12573,21 @@ static int Main() // (11,23): error CS0837: The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group. // bool b2 = delegate() { } is Del;// CS0837 Diagnostic(ErrorCode.ERR_LambdaInIsAs, "delegate() { } is Del").WithLocation(11, 23), + // (11,38): warning CS8848: Operator 'is' cannot be used here due to precedence. Use parentheses to disambiguate. + // bool b2 = delegate() { } is Del;// CS0837 + Diagnostic(ErrorCode.WRN_PrecedenceInversion, "is").WithArguments("is").WithLocation(11, 38), // (12,22): error CS0837: The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group. // Del d1 = () => { } as Del; // CS0837 Diagnostic(ErrorCode.ERR_LambdaInIsAs, "() => { } as Del").WithLocation(12, 22), + // (12,32): warning CS8848: Operator 'as' cannot be used here due to precedence. Use parentheses to disambiguate. + // Del d1 = () => { } as Del; // CS0837 + Diagnostic(ErrorCode.WRN_PrecedenceInversion, "as").WithArguments("as").WithLocation(12, 32), // (13,22): error CS0837: The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group. // Del d2 = delegate() { } as Del; // CS0837 - Diagnostic(ErrorCode.ERR_LambdaInIsAs, "delegate() { } as Del").WithLocation(13, 22) + Diagnostic(ErrorCode.ERR_LambdaInIsAs, "delegate() { } as Del").WithLocation(13, 22), + // (13,37): warning CS8848: Operator 'as' cannot be used here due to precedence. Use parentheses to disambiguate. + // Del d2 = delegate() { } as Del; // CS0837 + Diagnostic(ErrorCode.WRN_PrecedenceInversion, "as").WithArguments("as").WithLocation(13, 37) ); CreateCompilation(text, options: TestOptions.ReleaseDll.WithWarningLevel(5)).VerifyDiagnostics( // (10,23): error CS0837: The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group. From 55141e609605796f7a0f79ca0c60951943fd2410 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Sat, 5 Sep 2020 22:18:27 +0200 Subject: [PATCH 25/39] Fix an unintentional mistake --- .../CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs index 46da13633f614..b371f3f466435 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs @@ -1193,7 +1193,7 @@ public void AppliedCompilationRelaxationsOnModuleSupressesAssemblyAttributes(Out using System.Runtime.CompilerServices; [assembly: CompilationRelaxationsAttribute(0)] -", options: TestOptions.CreateTestOptions(outputKind, optimizationLevel)); +", options: TestOptions.CreateTestOptions(OutputKind.NetModule, optimizationLevel)); var reference = ModuleMetadata.CreateFromImage(referenceComp.EmitToArray()).GetReference(); From 8704b0606fd92a1f37fae9dd6c51bbdad45db504 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Sat, 5 Sep 2020 22:32:42 +0200 Subject: [PATCH 26/39] Apply suggestions from code review --- .../CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs | 2 +- .../CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs index b371f3f466435..ec3c49b036b9e 100644 --- a/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs +++ b/src/Compilers/CSharp/Test/Emit/Attributes/AttributeTests_Synthesized.cs @@ -1234,7 +1234,7 @@ public void AppliedRuntimeCompatibilityOnModuleSupressesAssemblyAttributes(Outpu using System.Runtime.CompilerServices; [assembly: RuntimeCompatibilityAttribute()] -", options: TestOptions.CreateTestOptions(outputKind, optimizationLevel)); +", options: TestOptions.CreateTestOptions(OutputKind.NetModule, optimizationLevel)); var reference = ModuleMetadata.CreateFromImage(referenceComp.EmitToArray()).GetReference(); diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs index 8d3f4cbceda63..da4fd02b8bd78 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs @@ -3637,7 +3637,7 @@ public static void Main() if ((1, null) is 4) {} if (null is var x1) {} if (Main is var x2) {} - if ((delegate {}) is var x3) {} + if (delegate {} is var x3) {} if ((1, null) is var x4) {} } } From df1674072774fe310ea616f82ca3a5a3d7589685 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Sat, 5 Sep 2020 22:37:03 +0200 Subject: [PATCH 27/39] Fix TestCollisionInsideFor2 --- .../Semantic/Semantics/NameCollisionTests.cs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NameCollisionTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NameCollisionTests.cs index c6f13efa5504e..25fab48e780cc 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NameCollisionTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NameCollisionTests.cs @@ -1259,7 +1259,7 @@ private string Property { get { - for (var name = from name in ""string"" orderby name select name; name != null; ) ; // 1931 TODO: There is an extra WRN_PrecedenceInversion + for (var name = from name in ""string"" orderby name select name; name != null; ) ; // 1931 for (IEnumerable name = null; name == from name in ""string"" orderby name select name; ) ; // 1931 for (IEnumerable name = null; name == null; name = from name in ""string"" orderby name select name ) ; // 1931 return string.Empty; @@ -1267,15 +1267,18 @@ private string Property } }"; CreateCompilationWithMscorlib40AndSystemCore(source).VerifyDiagnostics( + // (11,51): warning CS8848: Operator 'from' cannot be used here due to precedence. Use parentheses to disambiguate. + // for (IEnumerable name = null; name == from name in "string" orderby name select name; ) ; // 1931 + Diagnostic(ErrorCode.WRN_PrecedenceInversion, @"from name in ""string""").WithArguments("from").WithLocation(11, 51), // (10,34): error CS1931: The range variable 'name' conflicts with a previous declaration of 'name' - // for (var name = from name in "string" orderby name select name; name != null; ) ; // 1931 - Diagnostic(ErrorCode.ERR_QueryRangeVariableOverrides, "name").WithArguments("name"), + // for (var name = from name in "string" orderby name select name; name != null; ) ; // 1931 + Diagnostic(ErrorCode.ERR_QueryRangeVariableOverrides, "name").WithArguments("name").WithLocation(10, 34), // (11,56): error CS1931: The range variable 'name' conflicts with a previous declaration of 'name' - // for (IEnumerable name = null; name == from name in "string" orderby name select name; ) ; // 1931 - Diagnostic(ErrorCode.ERR_QueryRangeVariableOverrides, "name").WithArguments("name"), + // for (IEnumerable name = null; name == from name in "string" orderby name select name; ) ; // 1931 + Diagnostic(ErrorCode.ERR_QueryRangeVariableOverrides, "name").WithArguments("name").WithLocation(11, 56), // (12,69): error CS1931: The range variable 'name' conflicts with a previous declaration of 'name' - // for (IEnumerable name = null; name == null; name = from name in "string" orderby name select name ) ; // 1931 - Diagnostic(ErrorCode.ERR_QueryRangeVariableOverrides, "name").WithArguments("name")); + // for (IEnumerable name = null; name == null; name = from name in "string" orderby name select name ) ; // 1931 + Diagnostic(ErrorCode.ERR_QueryRangeVariableOverrides, "name").WithArguments("name").WithLocation(12, 69)); } [WorkItem(792744, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/792744")] From a56b3e299871d652c8495d0c0dc71eee97d7c2eb Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Sat, 5 Sep 2020 23:19:02 +0200 Subject: [PATCH 28/39] Add WRN_SyncAndAsyncEntryPoints to expected diagnostics --- .../CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs index b289065f45fbd..1c1ba5efc9130 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs @@ -1159,7 +1159,11 @@ async static Task Main(string[] args) System.Console.WriteLine(""Task Main""); } }"; - var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7_1)).VerifyDiagnostics(); + var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular.WithLanguageVersion(LanguageVersion.CSharp7_1)).VerifyDiagnostics( + // (10,23): warning CS8892: Method 'A.Main(string[])' will not be used as an entry point because a synchronous entry point 'A.Main()' was found. + // async static Task Main(string[] args) + Diagnostic(ErrorCode.WRN_SyncAndAsyncEntryPoints, "Main").WithArguments("A.Main(string[])", "A.Main()").WithLocation(10, 23) + ); CompileAndVerify(compilation, expectedOutput: "Non Task Main", expectedReturnCode: 0); } From 0b5bac7a050f549c68c7a86858b2e8f18193834c Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Sun, 6 Sep 2020 01:15:11 +0200 Subject: [PATCH 29/39] Add WRN_SyncAndAsyncEntryPoints to expected diagnostics --- .../CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs index 1c1ba5efc9130..91b139b4d72c4 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs @@ -1241,7 +1241,10 @@ async static Task Main(string[] args) System.Console.WriteLine(""Task Main""); } }"; - var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe.WithMainTypeName("A")).VerifyDiagnostics(); + var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe.WithMainTypeName("A")).VerifyDiagnostics( + // (10,23): warning CS8892: Method 'A.Main(string[])' will not be used as an entry point because a synchronous entry point 'A.Main()' was found. + // async static Task Main(string[] args) + Diagnostic(ErrorCode.WRN_SyncAndAsyncEntryPoints, \"Main\").WithArguments(\"A.Main(string[])\", \"A.Main()\").WithLocation(10, 23)); CompileAndVerify(compilation, expectedOutput: "Non Task Main", expectedReturnCode: 0); } From 42af28b3632c832efd79b6bd0c65fe4fb104aed2 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Mon, 14 Sep 2020 14:36:50 +0200 Subject: [PATCH 30/39] Update src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs --- .../Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs b/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs index eae3305358b7d..2d1a3f894938a 100644 --- a/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs +++ b/src/Compilers/CSharp/Test/Emit/PDB/CSharpDeterministicBuildCompilationTests.cs @@ -235,7 +235,7 @@ private static IEnumerable GetCompilationOptions() delaySign: null, platform: Platform.AnyCpu, generalDiagnosticOption: ReportDiagnostic.Default, - warningLevel: 5, + warningLevel: 4, specificDiagnosticOptions: null, concurrentBuild: true, deterministic: true, From 90a91ea3076f23fe2bad1fa46ab4d7908759530f Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Mon, 14 Sep 2020 15:01:37 +0200 Subject: [PATCH 31/39] Update CodeGenAsyncMainTests.cs --- src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs index 91b139b4d72c4..44ed71442cfc1 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncMainTests.cs @@ -1244,7 +1244,7 @@ async static Task Main(string[] args) var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe.WithMainTypeName("A")).VerifyDiagnostics( // (10,23): warning CS8892: Method 'A.Main(string[])' will not be used as an entry point because a synchronous entry point 'A.Main()' was found. // async static Task Main(string[] args) - Diagnostic(ErrorCode.WRN_SyncAndAsyncEntryPoints, \"Main\").WithArguments(\"A.Main(string[])\", \"A.Main()\").WithLocation(10, 23)); + Diagnostic(ErrorCode.WRN_SyncAndAsyncEntryPoints, "Main").WithArguments("A.Main(string[])", "A.Main()").WithLocation(10, 23)); CompileAndVerify(compilation, expectedOutput: "Non Task Main", expectedReturnCode: 0); } From 2a0d7539b6fbfe9c66ff37f860ae61dbf2bb9775 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Thu, 17 Sep 2020 18:51:43 +0200 Subject: [PATCH 32/39] Update SymbolErrorTests.cs --- src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs index 3ca62a48b1183..0cd734dc83e6c 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs @@ -13347,7 +13347,7 @@ interface I C this[C c] { get; set; } // 5, 6, 7 } "; - var comp = CreateCompilation(source, options: TestOptions.ReleaseDllWithWarningLevel5); + var comp = CreateCompilation(source); comp.VerifyDiagnostics( // (5,10): warning CS8897: 'C': static types cannot be used as parameters @@ -13373,7 +13373,7 @@ interface I Diagnostic(ErrorCode.WRN_ParameterIsStaticClass, "set").WithArguments("C").WithLocation(8, 24) ); - comp = CreateCompilation(source); + comp = CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningLevel(4)); comp.VerifyDiagnostics(); } From 157b655b4de88a8eba379c1a55972e440bbb1f19 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Thu, 17 Sep 2020 18:54:31 +0200 Subject: [PATCH 33/39] Update CodeGenFunctionPointersTests.cs --- .../CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs index 9904ff56f4401..22135cbb88fe0 100644 --- a/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs +++ b/src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenFunctionPointersTests.cs @@ -9544,6 +9544,9 @@ public static async Task Main() {} // (11,25): error CS8894: Cannot use 'Task' as a return type on a method attributed with 'UnmanagedCallersOnly'. // public static async Task Main() {} Diagnostic(ErrorCode.ERR_CannotUseManagedTypeInUnmanagedCallersOnly, "Task").WithArguments("System.Threading.Tasks.Task", "return").WithLocation(11, 25), + // (11,30): warning CS8892: Method 'D.Main()' will not be used as an entry point because a synchronous entry point 'C.Main()' was found. + // public static async Task Main() {} + Diagnostic(ErrorCode.WRN_SyncAndAsyncEntryPoints, "Main").WithArguments("D.Main()", "C.Main()").WithLocation(11, 30), // (11,30): warning CS1998: This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread. // public static async Task Main() {} Diagnostic(ErrorCode.WRN_AsyncLacksAwaits, "Main").WithLocation(11, 30) From dc816b22e6bafcdc872d384a5f03ce5dcfe77a67 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Thu, 17 Sep 2020 18:56:39 +0200 Subject: [PATCH 34/39] Update TopLevelStatementsTests.cs --- .../Test/Semantic/Semantics/TopLevelStatementsTests.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs index 69891681339ac..40e9b1ca3e22e 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/TopLevelStatementsTests.cs @@ -5283,7 +5283,10 @@ static void Main(string[] args) comp.VerifyEmitDiagnostics( // error CS8804: Cannot specify /main if there is a compilation unit with top-level statements. - Diagnostic(ErrorCode.ERR_SimpleProgramDisallowsMainType).WithLocation(1, 1) + Diagnostic(ErrorCode.ERR_SimpleProgramDisallowsMainType).WithLocation(1, 1), + // (12,23): warning CS8892: Method 'Program.Main(string[])' will not be used as an entry point because a synchronous entry point 'Program.Main()' was found. + // static async Task Main(string[] args) + Diagnostic(ErrorCode.WRN_SyncAndAsyncEntryPoints, "Main").WithArguments("Program.Main(string[])", "Program.Main()").WithLocation(12, 23) ); } From ff7d2ec5911470b9897e915a000d987c40822372 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 17 Sep 2020 20:29:12 +0000 Subject: [PATCH 35/39] Fix more tests --- .../CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs | 3 +++ .../CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs index da4fd02b8bd78..abf04c6e58a55 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/PatternMatchingTests.cs @@ -3667,6 +3667,9 @@ public static void Main() // (12,13): error CS0837: The first operand of an 'is' or 'as' operator may not be a lambda expression, anonymous method, or method group. // if (delegate {} is var x3) {} Diagnostic(ErrorCode.ERR_LambdaInIsAs, "delegate {} is var x3").WithLocation(12, 13), + // (12,25): warning CS8848: Operator 'is' cannot be used here due to precedence. Use parentheses to disambiguate. + // if (delegate {} is var x3) {} + Diagnostic(ErrorCode.WRN_PrecedenceInversion, "is").WithArguments("is").WithLocation(12, 25), // (13,13): error CS0023: Operator 'is' cannot be applied to operand of type '(int, )' // if ((1, null) is var x4) {} Diagnostic(ErrorCode.ERR_BadUnaryOp, "(1, null) is var x4").WithArguments("is", "(int, )").WithLocation(13, 13) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs index 0cd734dc83e6c..1107baac9e3c4 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs @@ -12978,12 +12978,12 @@ static void M(object o) }; // in /warn:5 we diagnose "is" and "as" operators with a static type. - var strictComp = CreateCompilation(text, options: TestOptions.ReleaseDll.WithWarningLevel(5)); + var strictComp = CreateCompilation(text); strictComp.VerifyDiagnostics(strictDiagnostics); // these rest of the diagnostics correspond to those produced by the native compiler. var regularDiagnostics = strictDiagnostics.Where(d => !d.Code.Equals((int)ErrorCode.WRN_StaticInAsOrIs)).ToArray(); - var regularComp = CreateCompilation(text); + var regularComp = CreateCompilation(text, options: TestOptions.ReleaseDll.WithWarningLevel(4)); regularComp.VerifyDiagnostics(regularDiagnostics); } @@ -13183,7 +13183,7 @@ object M(D p1) // CS0721 } "; var comp = DiagnosticsUtils.VerifyErrorsAndGetCompilationWithMscorlib(text, - // new ErrorDescription { Code = (int)ErrorCode.ERR_ParameterIsStaticClass, Line = 12, Column = 14 }, + new ErrorDescription { Code = (int)ErrorCode.WRN_ParameterIsStaticClass, Line = 12, Column = 14 }, new ErrorDescription { Code = (int)ErrorCode.ERR_ParameterIsStaticClass, Line = 16, Column = 21 }, new ErrorDescription { Code = (int)ErrorCode.ERR_ParameterIsStaticClass, Line = 22, Column = 20 }); From 133d393641ce562edb8a41f4ba4728b3d38e1405 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Thu, 17 Sep 2020 20:45:02 +0000 Subject: [PATCH 36/39] Remove ReleaseDllWithWarningLevel5 field --- src/Compilers/Test/Utilities/CSharp/TestOptions.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs index 42b2d7b91705f..fa9440a1c16a5 100644 --- a/src/Compilers/Test/Utilities/CSharp/TestOptions.cs +++ b/src/Compilers/Test/Utilities/CSharp/TestOptions.cs @@ -73,8 +73,6 @@ public static class TestOptions public static readonly CSharpCompilationOptions SigningReleaseModule = ReleaseModule.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider); public static readonly CSharpCompilationOptions SigningDebugDll = DebugDll.WithStrongNameProvider(SigningTestHelpers.DefaultDesktopStrongNameProvider); - public static readonly CSharpCompilationOptions ReleaseDllWithWarningLevel5 = ReleaseDll.WithWarningLevel(5); - public static readonly EmitOptions NativePdbEmit = EmitOptions.Default.WithDebugInformationFormat(DebugInformationFormat.Pdb); public static CSharpParseOptions WithStrictFeature(this CSharpParseOptions options) From 7815651b36fc2342f4b24fed184d9e488e1ef17e Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Fri, 18 Sep 2020 11:08:32 +0200 Subject: [PATCH 37/39] Update SymbolErrorTests.cs --- src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs index 1107baac9e3c4..db04e6adeb786 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs @@ -13183,7 +13183,7 @@ object M(D p1) // CS0721 } "; var comp = DiagnosticsUtils.VerifyErrorsAndGetCompilationWithMscorlib(text, - new ErrorDescription { Code = (int)ErrorCode.WRN_ParameterIsStaticClass, Line = 12, Column = 14 }, + new ErrorDescription { Code = (int)ErrorCode.WRN_ParameterIsStaticClass, Line = 12, Column = 14, IsWarning = true }, new ErrorDescription { Code = (int)ErrorCode.ERR_ParameterIsStaticClass, Line = 16, Column = 21 }, new ErrorDescription { Code = (int)ErrorCode.ERR_ParameterIsStaticClass, Line = 22, Column = 20 }); From b487ff84186a43279aecfb8f4d3dca01f36a0245 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Mon, 5 Oct 2020 15:54:42 +0200 Subject: [PATCH 38/39] Update InterpolationTests.cs --- .../CSharp/Test/Semantic/Semantics/InterpolationTests.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs index 80f1bc2da264e..62cc043b27220 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/InterpolationTests.cs @@ -4,6 +4,7 @@ #nullable disable +using Microsoft.CodeAnalysis.CSharp.Test.Utilities; using Microsoft.CodeAnalysis.Test.Utilities; using Roslyn.Test.Utilities; using System.Linq; From 79a70275179de2d0bc1ce4315355288e2827ceb0 Mon Sep 17 00:00:00 2001 From: Youssef Victor <31348972+Youssef1313@users.noreply.github.com> Date: Mon, 5 Oct 2020 15:56:55 +0200 Subject: [PATCH 39/39] Update SymbolErrorTests.cs --- src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs index e0eb8d1be6fef..a57aca699c534 100644 --- a/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs +++ b/src/Compilers/CSharp/Test/Symbol/Symbols/SymbolErrorTests.cs @@ -13241,6 +13241,8 @@ struct S } }"; CreateCompilation(source).VerifyDiagnostics( + // (12,14): warning CS8898: 'NS.D': static types cannot be used as return types + Diagnostic(ErrorCode.WRN_ReturnTypeIsStaticClass, "M").WithArguments("NS.D").WithLocation(12, 14), // (16,25): error CS0722: 'NS.C': static types cannot be used as return types Diagnostic(ErrorCode.ERR_ReturnTypeIsStaticClass, "F").WithArguments("NS.C").WithLocation(16, 25), // (23,29): error CS0722: 'NS.D': static types cannot be used as return types