Skip to content

Commit

Permalink
Merge pull request #1587 from filipw/feature/CheckForOverflowUnderflow
Browse files Browse the repository at this point in the history
 added support for CheckForOverflowUnderflow in csproj
  • Loading branch information
david-driscoll committed Aug 22, 2019
2 parents 42fe801 + a658910 commit aeb1b50
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
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

0 comments on commit aeb1b50

Please sign in to comment.