-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Add "Nullable" compilation option. #30479
Add "Nullable" compilation option. #30479
Conversation
/// <summary> | ||
/// Whether Nullable Reference Types feature is enabled globally. | ||
/// </summary> | ||
public bool? Nullable { 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.
bool? [](start = 15, length = 5)
Why use a nullable bool that defaults to null
, rather than a bool with default false
? (like AllowUnsafe
above) #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.
Why use a nullable bool that defaults to null, rather than a bool with default false? (like AllowUnsafe above)
This just preserves what we have today, the context can be in three different states. If we think that was not intentional or should change, that can be addressed later.
In reply to: 224928022 [](ancestors = 224928022)
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.
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.
Seems a PROTOTYPE comment then.
I'll open an issue for that
In reply to: 224934637 [](ancestors = 224934637,224930060,224928022)
@@ -123,7 +123,6 @@ Microsoft.CodeAnalysis.CSharp.CSharpCompilation.WithReferences(System.Collection | |||
Microsoft.CodeAnalysis.CSharp.CSharpCompilation.WithScriptCompilationInfo(Microsoft.CodeAnalysis.CSharp.CSharpScriptCompilationInfo info) -> Microsoft.CodeAnalysis.CSharp.CSharpCompilation | |||
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions | |||
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.AllowUnsafe.get -> bool | |||
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) -> void |
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.
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.
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.
Yes, I understand. We're supposed to ping them on any PR with public API change (whether shipped or unshipped).
In reply to: 224930250 [](ancestors = 224930250,224928238)
parsedArgs = DefaultParse(new[] { "a.cs", "/langversion:7.3" }, _baseDirectory); | ||
parsedArgs.Errors.Verify(); | ||
Assert.Null(parsedArgs.CompilationOptions.Nullable); | ||
} |
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.
} [](start = 8, length = 1)
If I run csc.exe /nullable+ /langversion:7.3 a.cs
, would I get two diagnostics (one from parsing command-line options and one from compilation diagnostics), or just one? #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.
If I run csc.exe /nullable+ /langversion:7.3 a.cs, would I get two diagnostics (one from parsing command-line options and one from compilation diagnostics), or just one?
Just the one reported by the command line parser. Note that both places report errors originating from options.
In reply to: 224929329 [](ancestors = 224929329)
@@ -32837,11 +32850,9 @@ static void G3<T>() where T : new() | |||
|
|||
// No warnings with C#7.3. |
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 warnings with C#7.3. [](start = 12, length = 26)
Stale comment? #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.
Stale comment?
I have no idea what this comment is about, there always were warnings for this scenario. Perhaps it refers to WRN_NullAsNonNullable warnings
In reply to: 224929938 [](ancestors = 224929938)
I think the #nonnull pragma should also be disallowed with older LangVersion, for same reason we disallow global option. #Resolved Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:284 in 33f5934. [](commit_id = 33f5934, deletion_comment = False) |
|
||
case "nullable-": | ||
if (value != null) | ||
break; |
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: surround with braces to match file. #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.
Nit: surround with braces to match file.
Matches the implementation for "checked" and I believe does not violate the style guidelines.
In reply to: 224930419 [](ancestors = 224930419)
Agree. Hence the PROTOTYPE comment above. This warning is not in scope for this PR because it is not focused on parsing the new directive. In reply to: 429479679 [](ancestors = 429479679) Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:284 in 33f5934. [](commit_id = 33f5934, deletion_comment = False) |
Never mindd, I misread. This test behaves correctly. #Closed Refers to: src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs:330 in 33f5934. [](commit_id = 33f5934, deletion_comment = False) |
} | ||
|
||
protected static CSharpCompilationOptions WithNonNullTypesFalse(CSharpCompilationOptions options = null) | ||
{ | ||
return (options ?? TestOptions.ReleaseDll).WithSpecificDiagnosticOptions( | ||
new[] { new System.Collections.Generic.KeyValuePair<string, ReportDiagnostic>("CS" + ((int)ErrorCode.WRN_PragmaNonNullTypes).ToString("0000"), ReportDiagnostic.Suppress) }); | ||
return (options ?? TestOptions.ReleaseDll).WithNullable(false); |
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.
WithNullable(false) [](start = 55, length = 19)
Do we have any tests that exercise the option null
? #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.
We should change Nullable
to a bool
so we don't need to test that case.
Nevermind, I guess allowing null
is a transitional state.
In reply to: 224933444 [](ancestors = 224933444)
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.
Do we have any tests that exercise the option null?
Yes. Those are all the tests that didn't apply NonNullTypes attribute on a module.
In reply to: 224933817 [](ancestors = 224933817,224933444)
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.
Any test that doesn't call WithNonNullTypesTrue/False
will use null
. So the case should be covered.
Closing
In reply to: 224933817 [](ancestors = 224933817,224933444)
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 but we need to follow-up on finalize public API shape for new option. Thanks
No description provided.