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

nullable switch no longer switches from warnings to errors #49392

Open
astrowalker opened this issue Nov 16, 2020 · 7 comments
Open

nullable switch no longer switches from warnings to errors #49392

astrowalker opened this issue Nov 16, 2020 · 7 comments
Assignees
Milestone

Comments

@astrowalker
Copy link

In a way, a follow up to #41605

Version Used:

VS 2019 Pro Version 16.8.1

Steps to Reproduce:

  1. Create Netstandard 2.1 project for example

  2. Enable Nullable

  3. Add "nullable" to WarningsAsErrors section, so with default values already present it shoudl be

    <WarningsAsErrors>nullable;NU1605</WarningsAsErrors>

Expected Behavior:

Nullable errors.

Actual Behavior:

Nullable warnings.

Notes:

  • when I use explicit values "CS8600;CS8602;CS8603;CS8613;CS8601;CS8625;CS8604;CS8618" instead of "nullable" it works (i.e. I got errors, not warnings)
  • not part of this report, but hard not to mention it -- when entering project properties in VS, there is "Nullable" combo with "Enable" value which produces warnings and "Warnings" value which produces... warnings. What is the point of it, and wouldn't it be more beneficial to have simple to understand "Disable|Warnings|Errors|Annotations" selection? Maybe it was supposed to work like this and the bug lies there?
@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 16, 2020
@RikkiGibson
Copy link
Contributor

I tried to reproduce and found that the command line build actually gave error diagnostics, but we still got warning diagnostics in the IDE. This might be an instance of #38371

@RikkiGibson
Copy link
Contributor

there is "Nullable" combo with "Enable" value which produces warnings and "Warnings" value which produces... warnings. What is the point of it, and wouldn't it be more beneficial to have simple to understand "Disable|Warnings|Errors|Annotations" selection?

It does sound odd that the combo box doesn't just enumerate the options which are available for the <Nullable> property. I took a look in my VS 16.8.1 project properties page and saw this:
image

So I don't know what caused your combo box to be missing the "annotations" value.

Also, this doc should clear up what "Enable" means versus "Warnings".

@jaredpar
Copy link
Member

Moving to IDE as this work sas expected in command line builds.

@jinujoseph jinujoseph added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Nov 17, 2020
@jinujoseph jinujoseph added this to the 16.9 milestone Nov 17, 2020
@astrowalker
Copy link
Author

astrowalker commented Nov 18, 2020

@RikkiGibson , I am not saying my combo box is missing Annotations, I am saying my combo box (as yours) has two entries (among others) -- Enable and Warnings that behave the same, they result in Warnings. In order to trigger errors (now not working) you have to go somewhere else, and switch transition from warnings to errors.

Just for the record, this was just a comment. The main point is there is problem with triggering errors.

@mavasani
Copy link
Contributor

The core issue here is that the logic to map special warnaserror value "nullable" to actual nullable IDs is inside the C# command line parser, which will not be part of compilation options for all hosts except command line build:

if (string.Equals(id, "nullable", StringComparison.OrdinalIgnoreCase))
{
foreach (var errorCode in ErrorFacts.NullableWarnings)
{
yield return errorCode;
}
yield return CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_MissingNonNullTypesContextForAnnotation);
yield return CSharp.MessageProvider.Instance.GetIdForErrorCode((int)ErrorCode.WRN_MissingNonNullTypesContextForAnnotationInGeneratedCode);
}

This issue can be fixed in couple of possible ways:

  1. Compiler exposes a public API that maps "nullable" keyword to set of CS diagnostic IDs so other hosts can replicate this functionality.
  2. The above logic to convert "nullable" to CS diagnostic IDs is moved to CompilationOptions constructors which set CompilationOptions.SpecificDiagnosticOptions.

Latter seems more preferable as it will implicitly fix all diagnostic hosts - though, I'll let the compiler team decide. Moving the issue back to Area-Compilers.

@mavasani mavasani removed this from the 16.9 milestone Nov 18, 2020
@mavasani mavasani removed their assignment Nov 18, 2020
@RikkiGibson RikkiGibson self-assigned this Nov 18, 2020
@RikkiGibson
Copy link
Contributor

thanks for the detailed analysis!

@JoeRobich
Copy link
Member

O# is handling this by maintaining their own mapping - OmniSharp/omnisharp-roslyn#2406 - which is not ideal.

@jaredpar jaredpar modified the milestones: Compiler.Next, Backlog Sep 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants