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

WarningsAsErrors for nullable doesn't work as expected. #2630

Open
furai opened this issue Aug 15, 2024 · 2 comments
Open

WarningsAsErrors for nullable doesn't work as expected. #2630

furai opened this issue Aug 15, 2024 · 2 comments

Comments

@furai
Copy link

furai commented Aug 15, 2024

Hey,

I'm creating new issue as requested:

@furai Please create a new one.

Originally posted by @JoeRobich in #2292 (comment)

I'm using latest omnisharp from the master branch with Visual Studio Code.
When setting nullable warnings as errors - msbuild fails but omnisharp still treats these warnings as warnings instead of errors.

Output from vscode:
image

Dotnet build:

$ dotnet build

MSBuild version 17.8.5+b5265ef37 for .NET
  Determining projects to restore...
  Restored test.csproj (in 140 ms).
Program.cs(8,22): error CS8600: Converting null literal or possible null value to non-nullable type. [test.csproj]

Build FAILED.

Program.cs(8,22): error CS8600: Converting null literal or possible null value to non-nullable type. [test.csproj]
    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:02.10

If I add CS8600 to WarnigngsAsErrors like this:

...
    <WarningsAsErrors>nullable,CS8600</WarningsAsErrors>
...

Then it shows up as error as expected:
image

Minimal reproducible example:

Program.cs

namespace test;

public class Program
{
    public static void Main(string[] args)
    {
        string? foo = null;
        string bar = null;
        Console.WriteLine(foo + bar);
    }
}

test.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <WarningsAsErrors>nullable</WarningsAsErrors>
  </PropertyGroup>

</Project>

Expected behaviour:

  • Omnisharp should treat nullable warnings as errors when WarningsAsErrors is set to nullable in the project file without adding any extra warnings to WarningsAsErrors to match the behaviour of msbuild.

Thank you for your time, I really appreciate it.

Cheers,
Furai

PS At first I tried to tackle this issue on my own, I've cloned the repository and TBH I got stuck on build process for linux. It seems that base project is kind of outdated. Something should be done about using nuget on linux. Probably the best solution is to move from packages.config to PackageReference and use dotnet restore instead of nuget install. I'm not C# wizard and I know nearly nothing about this project so I'm not sure if this is the best solution. I'm just sharing my thoughts. I hope that's fine.

@JoeRobich
Copy link
Member

What is odd is that we have a test for this scenario, but I am able to reproduce your bug locally. One difference is that the test is targeting net6.0. Changing your repro to net6.0 causes O# to return it as an error. Now to figure out why we are getting warnings when targeting net8.0.

@ryze312
Copy link

ryze312 commented Nov 13, 2024

This issue also occurs with CS8509, Omnisharp treats it as a warning, while building fails as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants