-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Implement compiler /warnversion flag and one "wave" warning #45750
Conversation
Fixes dotnet#45702 Fixes dotnet#45744 Related to dotnet#45701 and dotnet#45704
Looks like you're missing the MSBuild hookup to the switch here. #Resolved |
See #45701 for the work breakdown. This is the compiler portion only. The MSBuild hookup is tracked by dotnet/roslyn-analyzers#3823 and @jmarolf plans to implement it. #Resolved |
@jaredpar yep I am going to build on top of this #Resolved |
CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningVersion(4.9m)).VerifyDiagnostics(); | ||
CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningVersion(5m)).VerifyDiagnostics(whenWave5); | ||
CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningVersion(5.0m)).VerifyDiagnostics(whenWave5); | ||
CreateCompilation(source, options: TestOptions.ReleaseDll.WithWarningVersion(5.1m)).VerifyDiagnostics(whenWave5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a possibility of a platform version like "dotnet 5.10", which is later than dotnet 5.2? #ByDesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we are planning to use minor versions for .net core at all (though the current version is 3.1). It seems unlikely we would have so many minor versions without a major version bump. Also, many people would be confused if we did that.
In reply to: 452460481 [](ancestors = 452460481)
@@ -4617,7 +4620,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ | |||
-warnaserror[+|-] Report all warnings as errors | |||
-warnaserror[+|-]:<warn list> Report specific warnings as errors | |||
(use "nullable" for all nullability warnings) | |||
-warn:<n> Set warning level (0-4) (Short form: -w) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we keep the old setting, since still works? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, since we do not want to encourage people to use it. The UI for setting this is also being removed from VS.
In reply to: 452492523 [](ancestors = 452492523)
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.CSharpCompilationOptions(Microsoft.CodeAnalysis.OutputKind outputKind, bool reportSuppressedDiagnostics = false, string moduleName = null, string mainTypeName = null, string scriptClassName = null, System.Collections.Generic.IEnumerable<string> usings = null, Microsoft.CodeAnalysis.OptimizationLevel optimizationLevel = Microsoft.CodeAnalysis.OptimizationLevel.Debug, bool checkOverflow = false, bool allowUnsafe = false, string cryptoKeyContainer = null, string cryptoKeyFile = null, System.Collections.Immutable.ImmutableArray<byte> cryptoPublicKey = default(System.Collections.Immutable.ImmutableArray<byte>), bool? delaySign = null, Microsoft.CodeAnalysis.Platform platform = Microsoft.CodeAnalysis.Platform.AnyCpu, Microsoft.CodeAnalysis.ReportDiagnostic generalDiagnosticOption = Microsoft.CodeAnalysis.ReportDiagnostic.Default, int warningLevel = 4, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Microsoft.CodeAnalysis.ReportDiagnostic>> specificDiagnosticOptions = null, bool concurrentBuild = true, bool deterministic = false, Microsoft.CodeAnalysis.XmlReferenceResolver xmlReferenceResolver = null, Microsoft.CodeAnalysis.SourceReferenceResolver sourceReferenceResolver = null, Microsoft.CodeAnalysis.MetadataReferenceResolver metadataReferenceResolver = null, Microsoft.CodeAnalysis.AssemblyIdentityComparer assemblyIdentityComparer = null, Microsoft.CodeAnalysis.StrongNameProvider strongNameProvider = null, bool publicSign = false, Microsoft.CodeAnalysis.MetadataImportOptions metadataImportOptions = Microsoft.CodeAnalysis.MetadataImportOptions.Public, Microsoft.CodeAnalysis.NullableContextOptions nullableContextOptions = Microsoft.CodeAnalysis.NullableContextOptions.Disable, decimal warningVersion = 0) -> void | ||
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.CSharpCompilationOptions(Microsoft.CodeAnalysis.OutputKind outputKind, bool reportSuppressedDiagnostics, string moduleName, string mainTypeName, string scriptClassName, System.Collections.Generic.IEnumerable<string> usings, Microsoft.CodeAnalysis.OptimizationLevel optimizationLevel, bool checkOverflow, bool allowUnsafe, string cryptoKeyContainer, string cryptoKeyFile, System.Collections.Immutable.ImmutableArray<byte> cryptoPublicKey, bool? delaySign, Microsoft.CodeAnalysis.Platform platform, Microsoft.CodeAnalysis.ReportDiagnostic generalDiagnosticOption, int warningLevel, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Microsoft.CodeAnalysis.ReportDiagnostic>> specificDiagnosticOptions, bool concurrentBuild, bool deterministic, Microsoft.CodeAnalysis.XmlReferenceResolver xmlReferenceResolver, Microsoft.CodeAnalysis.SourceReferenceResolver sourceReferenceResolver, Microsoft.CodeAnalysis.MetadataReferenceResolver metadataReferenceResolver, Microsoft.CodeAnalysis.AssemblyIdentityComparer assemblyIdentityComparer, Microsoft.CodeAnalysis.StrongNameProvider strongNameProvider, bool publicSign, Microsoft.CodeAnalysis.MetadataImportOptions metadataImportOptions, Microsoft.CodeAnalysis.NullableContextOptions nullableContextOptions) -> void | ||
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.WarningVersion.get -> decimal | ||
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.WithWarningVersion(decimal warningVersion) -> Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decimal [](start = 74, length = 7)
Should we use an enum (like we do for WithLanguageVersion
)? #ByDesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, as there is not a fixed set of values you can specify.
In reply to: 452493235 [](ancestors = 452493235)
@@ -4617,7 +4620,9 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ | |||
-warnaserror[+|-] Report all warnings as errors | |||
-warnaserror[+|-]:<warn list> Report specific warnings as errors | |||
(use "nullable" for all nullability warnings) | |||
-warn:<n> Set warning level (0-4) (Short form: -w) | |||
-warnversion:<n> Enable recently introduced warnings. Default '0'. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we support -warnversion:?
as we do for -langversion:?
#ByDesign
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No plans to do so, since there is not a fixed set of values you can specify.
In reply to: 452493597 [](ancestors = 452493597)
/// the warning wave in which it was introduced. | ||
/// </summary> | ||
/// <param name="code"></param> | ||
/// <returns></returns> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: xml can be cleaned up #Closed
`k` or later is used to compile the code. | ||
|
||
The default warning version is `0` (produce no optional warnings). | ||
Our first warning under control of `/warnversion` was introduced in version `5`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: may be good to mention this corresponds to .NET 5 #Closed
@@ -792,7 +792,7 @@ private void CheckLiftedBinOp(BoundBinaryOperator node) | |||
|
|||
string always = node.OperatorKind.Operator() == BinaryOperatorKind.NotEqual ? "true" : "false"; | |||
|
|||
if (_compilation.FeatureStrictEnabled || !node.OperatorKind.IsUserDefined()) | |||
if (_compilation.FeatureStrictEnabled || !node.OperatorKind.IsUserDefined() || ErrorCode.WRN_NubExprIsConstBool2.GetWarningVersion() <= this._compilation.Options.WarningVersion) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FeatureStrictEnabled [](start = 37, length = 20)
Should we assume that FeatureStrictEnabled
is true when warn version >=5? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. FeatureStrictEnabled
is orthogonal and most of the diagnostics under its control are currently errors. Once we migrate something to a warning wave we can remove it from FeatureStrictEnabled
after a period of time sufficient for people to start using it.
In reply to: 452495746 [](ancestors = 452495746)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done with review pass (iteration 4)
@jcouv I have responded to your comments. Do you have any others? |
@gafter I do think someone needs to update the compiler MSBuild tasks to accept this new option right? I want to be able to make this change to the msbuild targets <Csc Resources="@(_SatelliteAssemblyResourceInputs)"
Sources="$(_AssemblyInfoFile)"
OutputAssembly="$(_OutputAssembly)"
References="@(ReferencePath)"
KeyContainer="$(KeyContainerName)"
KeyFile="$(KeyOriginatorFile)"
NoConfig="true"
NoLogo="$(NoLogo)"
NoStandardLib="$(NoCompilerStandardLib)"
PublicSign="$(PublicSign)"
DelaySign="$(DelaySign)"
Deterministic="$(Deterministic)"
DisabledWarnings="$(DisabledWarnings)"
WarningLevel="$(WarningLevel)"
WarningsAsErrors="$(WarningsAsErrors)"
WarningsNotAsErrors="$(WarningsNotAsErrors)"
+ WarnVersion="$(WarnVersion)"
TargetType="Library"
ToolExe="$(CscToolExe)"
ToolPath="$(CscToolPath)"
UseSharedCompilation="$(UseSharedCompilation)"> But I believe the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM Thanks (iteration 6)
as part of .NET 5. | ||
If you want the compiler to produce all applicable warnings, you can specify | ||
`/warnversion=9999`. | ||
In the project file, the property used to specify the warning version is `AnalysisLevel`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not even call the MSBuild project property WarnVersion
? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think because it is intended it be used to specify a level of analysis for analyzers to use too.
In reply to: 453250128 [](ancestors = 453250128)
@@ -0,0 +1,25 @@ | |||
# /warnversion warning "waves" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this flag be added/respected for VB as well? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my understanding is that it would not be at this time, but it could be added later if there are warnings we want to add #Resolved
/// associated with the warning. Use zero to get none of the versioned warnings, or a large number like 9999 | ||
/// to get all of the versioned warnings. The first version that enables some warnings is version 5. | ||
/// </remarks> | ||
public decimal WarningVersion { get; private set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why decimal
and not Version
, given the property itself is named version? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our first warning under control of `/warnversion` was introduced in version `5` | ||
as part of .NET 5. | ||
If you want the compiler to produce all applicable warnings, you can specify | ||
`/warnversion=9999`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this instead be a special string, say latest
instead of a number? This would also match the LangVersion
property values. #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I (mistakenly?) thought you were planning to do that under dotnet/roslyn-analyzers#3823. Should I add that to this PR? In reply to: 656830706 [](ancestors = 656830706) |
@@ -503,7 +503,7 @@ class D | |||
public int P2 { get; set; } | |||
} | |||
"; | |||
await VerifyItemExistsAsync(markup, "P1"); | |||
await VerifyNoItemsExistAsync(markup); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did this sneak in from another unrelated PR? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, just fixing a test broken in the merged branch. Probably broken in master too. See #45990 (comment) #Resolved
@gafter so I believe there are several phases to this:
Each of these needs to go in, for the most part, in the order listed but I don't think we should block this PR on that. Once the compiler team is ok with the changes to the commandline api lets merge this and then I'll rebase the downstream PRs with whatever changes are made |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Auto-approval
It appears the latest version of the Runtime\SDK ( Compiling gives:
Any suggestions to unblock? Using |
@steveharter Until this version of the compiler is integrated, use warning level 4. |
@gafter the .csproj is not specifying any warning level; it's using the default. I also tried creating a new console app with the same error. Is there an environment variable? |
You can specify |
For those internal to microsoft this contains the fix on the VS side. internal vs builds will be working within a day. |
@jmarolf the |
@jmarolf does this also require a down-level fix in VS? (older VS, newer compiler?) |
@steveharter .NET 5 is only going to work with VS 16.8. Moving forward you are going to need either the .NET 5 SDK to build or VS 16.8 |
Fixes #45702
Fixes #45744
Related to #45701 and #45704