Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added support for CheckForOverflowUnderflow in csproj #1587

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
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))

## [1.34.2] - 2019-08-16
* Update to Roslyn `3.3.0-beta2-19401-05` which fixes a 1.34.1 regression resulting in StackOverflowException on code analysis of partial classes (PR: [#1579](https://github.com/OmniSharp/omnisharp-roslyn/pull/1579))
* Added support for reading C# 8.0 `Nullable` setting from csproj files (and dropped support for `NullableContextOptions` - based on the LDM decision to [rename the MSBuild property](https://github.com/dotnet/roslyn/issues/35432) ([#1573](https://github.com/OmniSharp/omnisharp-roslyn/pull/1573))
Expand Down
12 changes: 9 additions & 3 deletions src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.ProjectData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> PreprocessorSymbolNames { get; }
public ImmutableArray<string> SuppressedDiagnosticIds { get; }
Expand Down Expand Up @@ -80,6 +81,7 @@ private ProjectData(
LanguageVersion languageVersion,
NullableContextOptions nullableContextOptions,
bool allowUnsafeCode,
bool checkForOverflowUnderflow,
string documentationFile,
ImmutableArray<string> preprocessorSymbolNames,
ImmutableArray<string> suppressedDiagnosticIds,
Expand Down Expand Up @@ -108,6 +110,7 @@ private ProjectData(
LanguageVersion = languageVersion;
NullableContextOptions = nullableContextOptions;
AllowUnsafeCode = allowUnsafeCode;
CheckForOverflowUnderflow = checkForOverflowUnderflow;
DocumentationFile = documentationFile;
PreprocessorSymbolNames = preprocessorSymbolNames.EmptyIfDefault();
SuppressedDiagnosticIds = suppressedDiagnosticIds.EmptyIfDefault();
Expand All @@ -130,6 +133,7 @@ private ProjectData(
LanguageVersion languageVersion,
NullableContextOptions nullableContextOptions,
bool allowUnsafeCode,
bool checkForOverflowUnderflow,
string documentationFile,
ImmutableArray<string> preprocessorSymbolNames,
ImmutableArray<string> suppressedDiagnosticIds,
Expand All @@ -146,7 +150,7 @@ private ProjectData(
RuleSet ruleset,
ImmutableDictionary<string, string> 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();
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
}
Expand Down
1 change: 1 addition & 0 deletions src/OmniSharp.MSBuild/ProjectFile/ProjectFileInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> PreprocessorSymbolNames => _data.PreprocessorSymbolNames;
public ImmutableArray<string> SuppressedDiagnosticIds => _data.SuppressedDiagnosticIds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions src/OmniSharp.MSBuild/ProjectFile/PropertyNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions test-assets/test-projects/HelloWorld/HelloWorld.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<TargetFramework>netcoreapp2.1</TargetFramework>
<LangVersion>7.1</LangVersion>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
</PropertyGroup>

</Project>
5 changes: 5 additions & 0 deletions tests/OmniSharp.MSBuild.Tests/ProjectFileInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down