diff --git a/CHANGELOG.md b/CHANGELOG.md index b7bd3b22f9..0ff52c9511 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ All changes to the project will be documented in this file. ## [1.34.3] - not yet released +* Added support for `CheckForOverflowUnderflow ` in csproj files (PR: [#1587](https://github.com/OmniSharp/omnisharp-roslyn/pull/1587)) * Updated LSP libraries to 0.13 which fixes problems with clients not supporting dynamic registrations. ([#1505](https://github.com/OmniSharp/omnisharp-roslyn/issues/1505), [#1525](https://github.com/OmniSharp/omnisharp-roslyn/issues/1525), PR: [#1562](https://github.com/OmniSharp/omnisharp-roslyn/pull/1562)) ## [1.34.2] - 2019-08-16 diff --git a/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.ProjectData.cs b/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.ProjectData.cs index a42b59f1af..ad470bda02 100644 --- a/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.ProjectData.cs +++ b/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.ProjectData.cs @@ -35,6 +35,7 @@ private class ProjectData public LanguageVersion LanguageVersion { get; } public NullableContextOptions NullableContextOptions { get; } public bool AllowUnsafeCode { get; } + public bool CheckForOverflowUnderflow { get; } public string DocumentationFile { get; } public ImmutableArray PreprocessorSymbolNames { get; } public ImmutableArray SuppressedDiagnosticIds { get; } @@ -80,6 +81,7 @@ private ProjectData( LanguageVersion languageVersion, NullableContextOptions nullableContextOptions, bool allowUnsafeCode, + bool checkForOverflowUnderflow, string documentationFile, ImmutableArray preprocessorSymbolNames, ImmutableArray suppressedDiagnosticIds, @@ -108,6 +110,7 @@ private ProjectData( LanguageVersion = languageVersion; NullableContextOptions = nullableContextOptions; AllowUnsafeCode = allowUnsafeCode; + CheckForOverflowUnderflow = checkForOverflowUnderflow; DocumentationFile = documentationFile; PreprocessorSymbolNames = preprocessorSymbolNames.EmptyIfDefault(); SuppressedDiagnosticIds = suppressedDiagnosticIds.EmptyIfDefault(); @@ -130,6 +133,7 @@ private ProjectData( LanguageVersion languageVersion, NullableContextOptions nullableContextOptions, bool allowUnsafeCode, + bool checkForOverflowUnderflow, string documentationFile, ImmutableArray preprocessorSymbolNames, ImmutableArray suppressedDiagnosticIds, @@ -146,7 +150,7 @@ private ProjectData( RuleSet ruleset, ImmutableDictionary referenceAliases) : this(guid, name, assemblyName, targetPath, outputPath, intermediateOutputPath, projectAssetsFile, - configuration, platform, targetFramework, targetFrameworks, outputKind, languageVersion, nullableContextOptions, allowUnsafeCode, + configuration, platform, targetFramework, targetFrameworks, outputKind, languageVersion, nullableContextOptions, allowUnsafeCode, checkForOverflowUnderflow, documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile, treatWarningsAsErrors, defaultNamespace, ruleset) { SourceFiles = sourceFiles.EmptyIfDefault(); @@ -183,6 +187,7 @@ public static ProjectData Create(MSB.Evaluation.Project project) var languageVersion = PropertyConverter.ToLanguageVersion(project.GetPropertyValue(PropertyNames.LangVersion)); var allowUnsafeCode = PropertyConverter.ToBoolean(project.GetPropertyValue(PropertyNames.AllowUnsafeBlocks), defaultValue: false); + var checkForOverflowUnderflow = PropertyConverter.ToBoolean(project.GetPropertyValue(PropertyNames.CheckForOverflowUnderflow), defaultValue: false); var outputKind = PropertyConverter.ToOutputKind(project.GetPropertyValue(PropertyNames.OutputType)); var nullableContextOptions = PropertyConverter.ToNullableContextOptions(project.GetPropertyValue(PropertyNames.Nullable)); var documentationFile = project.GetPropertyValue(PropertyNames.DocumentationFile); @@ -194,7 +199,7 @@ public static ProjectData Create(MSB.Evaluation.Project project) return new ProjectData( guid, name, assemblyName, targetPath, outputPath, intermediateOutputPath, projectAssetsFile, - configuration, platform, targetFramework, targetFrameworks, outputKind, languageVersion, nullableContextOptions, allowUnsafeCode, + configuration, platform, targetFramework, targetFrameworks, outputKind, languageVersion, nullableContextOptions, allowUnsafeCode, checkForOverflowUnderflow, documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile, treatWarningsAsErrors, defaultNamespace, ruleset: null); } @@ -223,6 +228,7 @@ public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance) var languageVersion = PropertyConverter.ToLanguageVersion(projectInstance.GetPropertyValue(PropertyNames.LangVersion)); var allowUnsafeCode = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.AllowUnsafeBlocks), defaultValue: false); + var checkForOverflowUnderflow = PropertyConverter.ToBoolean(projectInstance.GetPropertyValue(PropertyNames.CheckForOverflowUnderflow), defaultValue: false); var outputKind = PropertyConverter.ToOutputKind(projectInstance.GetPropertyValue(PropertyNames.OutputType)); var nullableContextOptions = PropertyConverter.ToNullableContextOptions(projectInstance.GetPropertyValue(PropertyNames.Nullable)); var documentationFile = projectInstance.GetPropertyValue(PropertyNames.DocumentationFile); @@ -281,7 +287,7 @@ public static ProjectData Create(MSB.Execution.ProjectInstance projectInstance) return new ProjectData(guid, name, assemblyName, targetPath, outputPath, intermediateOutputPath, projectAssetsFile, configuration, platform, targetFramework, targetFrameworks, - outputKind, languageVersion, nullableContextOptions, allowUnsafeCode, documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, + outputKind, languageVersion, nullableContextOptions, allowUnsafeCode, checkForOverflowUnderflow, documentationFile, preprocessorSymbolNames, suppressedDiagnosticIds, signAssembly, assemblyOriginatorKeyFile, sourceFiles, projectReferences, references.ToImmutable(), packageReferences, analyzers, additionalFiles, treatWarningsAsErrors, defaultNamespace, ruleset, referenceAliases.ToImmutableDictionary()); } diff --git a/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs b/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs index 2a2d81221d..085b219524 100644 --- a/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs +++ b/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs @@ -37,6 +37,7 @@ internal partial class ProjectFileInfo public LanguageVersion LanguageVersion => _data.LanguageVersion; public NullableContextOptions NullableContextOptions => _data.NullableContextOptions; public bool AllowUnsafeCode => _data.AllowUnsafeCode; + public bool CheckForOverflowUnderflow => _data.CheckForOverflowUnderflow; public string DocumentationFile => _data.DocumentationFile; public ImmutableArray PreprocessorSymbolNames => _data.PreprocessorSymbolNames; public ImmutableArray SuppressedDiagnosticIds => _data.SuppressedDiagnosticIds; diff --git a/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfoExtensions.cs b/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfoExtensions.cs index f6a87674ed..ada58e331a 100644 --- a/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfoExtensions.cs +++ b/src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfoExtensions.cs @@ -16,8 +16,9 @@ public static CSharpCompilationOptions CreateCompilationOptions(this ProjectFile { var compilationOptions = new CSharpCompilationOptions(projectFileInfo.OutputKind); - compilationOptions = compilationOptions.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default); - compilationOptions = compilationOptions.WithSpecificDiagnosticOptions(projectFileInfo.GetDiagnosticOptions()); + compilationOptions = compilationOptions.WithAssemblyIdentityComparer(DesktopAssemblyIdentityComparer.Default) + .WithSpecificDiagnosticOptions(projectFileInfo.GetDiagnosticOptions()) + .WithOverflowChecks(projectFileInfo.CheckForOverflowUnderflow); if (projectFileInfo.AllowUnsafeCode) { diff --git a/src/OmniSharp.MSBuild/ProjectFile/PropertyNames.cs b/src/OmniSharp.MSBuild/ProjectFile/PropertyNames.cs index 572086c237..d28f8e1a49 100644 --- a/src/OmniSharp.MSBuild/ProjectFile/PropertyNames.cs +++ b/src/OmniSharp.MSBuild/ProjectFile/PropertyNames.cs @@ -9,6 +9,7 @@ internal static class PropertyNames public const string BuildProjectReferences = nameof(BuildProjectReferences); public const string BuildingInsideVisualStudio = nameof(BuildingInsideVisualStudio); public const string BypassFrameworkInstallChecks = nameof(BypassFrameworkInstallChecks); + public const string CheckForOverflowUnderflow = nameof(CheckForOverflowUnderflow); public const string Configuration = nameof(Configuration); public const string CscToolExe = nameof(CscToolExe); public const string CscToolPath = nameof(CscToolPath); diff --git a/test-assets/test-projects/HelloWorld/HelloWorld.csproj b/test-assets/test-projects/HelloWorld/HelloWorld.csproj index ef7ac872d2..fc3240a1bd 100644 --- a/test-assets/test-projects/HelloWorld/HelloWorld.csproj +++ b/test-assets/test-projects/HelloWorld/HelloWorld.csproj @@ -5,6 +5,7 @@ netcoreapp2.1 7.1 true + true diff --git a/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs b/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs index 21905c24c0..46e10745e3 100644 --- a/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs +++ b/tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs @@ -64,6 +64,7 @@ public async Task HelloWorld_has_correct_property_values() var compilationOptions = projectFileInfo.CreateCompilationOptions(); Assert.Equal(ReportDiagnostic.Error, compilationOptions.GeneralDiagnosticOption); + Assert.True(compilationOptions.CheckOverflow); } } @@ -86,6 +87,10 @@ public async Task HelloWorldSlim_has_correct_property_values() Assert.Equal(3, projectFileInfo.SourceFiles.Length); // Program.cs, AssemblyInfo.cs, AssemblyAttributes.cs Assert.Equal("Debug", projectFileInfo.Configuration); Assert.Equal("AnyCPU", projectFileInfo.Platform); + + var compilationOptions = projectFileInfo.CreateCompilationOptions(); + Assert.Equal(ReportDiagnostic.Default, compilationOptions.GeneralDiagnosticOption); + Assert.False(compilationOptions.CheckOverflow); } }