-
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
Address NRT issues found by targeting net5.0 #50895
Changes from 5 commits
b844dc6
bd953a3
3d29d69
fa95138
00fb401
4ecfa02
012966c
910f407
d837ee9
a0496e9
2752737
6a48567
cf72285
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,11 +19,11 @@ public static T EnsureInitialized<T>([NotNull] ref T? target, Func<T> valueFacto | |
=> LazyInitializer.EnsureInitialized<T>(ref target!, valueFactory); | ||
|
||
/// <inheritdoc cref="LazyInitializer.EnsureInitialized{T}(ref T, ref bool, ref object)"/> | ||
public static T EnsureInitialized<T>([NotNull] ref T? target, ref bool initialized, [NotNull] ref object? syncLock) | ||
public static T EnsureInitialized<T>([NotNull] ref T? target, ref bool initialized, [NotNullIfNotNull("syncLock")] ref object? syncLock) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's clever ;-) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I copied the annotation from net5.0. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Makes sense. Thanks |
||
=> LazyInitializer.EnsureInitialized<T>(ref target!, ref initialized, ref syncLock); | ||
|
||
/// <inheritdoc cref="LazyInitializer.EnsureInitialized{T}(ref T, ref bool, ref object, Func{T})"/> | ||
public static T EnsureInitialized<T>([NotNull] ref T? target, ref bool initialized, [NotNull] ref object? syncLock, Func<T> valueFactory) | ||
public static T EnsureInitialized<T>([NotNull] ref T? target, ref bool initialized, [NotNullIfNotNull("syncLock")] ref object? syncLock, Func<T> valueFactory) | ||
=> LazyInitializer.EnsureInitialized<T>(ref target!, ref initialized, ref syncLock, valueFactory); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,7 @@ public static IEnumerable<TNode> GetCurrentNodes<TNode>(this SyntaxNode root, TN | |
/// </summary> | ||
/// <param name="root">The root of the subtree containing the current node corresponding to the original tracked node.</param> | ||
/// <param name="node">The node instance originally tracked.</param> | ||
public static TNode GetCurrentNode<TNode>(this SyntaxNode root, TNode node) | ||
public static TNode? GetCurrentNode<TNode>(this SyntaxNode root, TNode node) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one is public API bug, and causing bug in Features layer. |
||
where TNode : SyntaxNode | ||
{ | ||
return GetCurrentNodes(root, node).SingleOrDefault(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -175,7 +175,7 @@ protected override async Task FixAllAsync( | |
var root = await document.GetRequiredSyntaxRootAsync(cancellationToken).ConfigureAwait(false); | ||
var spanNodes = diagnostics.SelectAsArray( | ||
d => root.FindNode(d.Location.SourceSpan, getInnermostNodeForTie: true) | ||
.GetAncestorsOrThis<TExpressionSyntax>().FirstOrDefault()); | ||
.GetAncestorsOrThis<TExpressionSyntax>().First()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code looks very confidential about it (defensive in outer code but not this), so I changed to |
||
|
||
await editor.ApplyExpressionLevelSemanticEditsAsync( | ||
document, spanNodes, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,7 +82,7 @@ public XElement ToXElement() => | |
new("CodeStyleOption", // Ensure that we use "CodeStyleOption" as the name for back compat. | ||
new XAttribute(nameof(SerializationVersion), SerializationVersion), | ||
new XAttribute("Type", GetTypeNameForSerialization()), | ||
new XAttribute(nameof(Value), GetValueForSerialization()), | ||
new XAttribute(nameof(Value), GetValueForSerialization()!), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's going on here? GetValueForSerialization is pretty directly marked as null-returning; can we revise that and push the suppression somewhere closer if possible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's only nullable when using uninitialized value with T=string. There could be a later refactor on that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess I'd say in that case we should:
Now I'm also a bit confused because the docs for the type say that T is only allowed to be bool or an enum, so clearly we are breaking that rule somewhere...? @mavasani or @jmarolf any idea if nulls are supposed to be supported here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jmarolf confirmed that we don't expect to get nulls here, so current code is good. |
||
new XAttribute(nameof(DiagnosticSeverity), Notification.Severity.ToDiagnosticSeverity() ?? DiagnosticSeverity.Hidden)); | ||
|
||
private object? GetValueForSerialization() | ||
|
@@ -133,7 +133,7 @@ public static CodeStyleOption2<T> FromXElement(XElement element) | |
var typeAttribute = element.Attribute("Type"); | ||
var valueAttribute = element.Attribute(nameof(Value)); | ||
var severityAttribute = element.Attribute(nameof(DiagnosticSeverity)); | ||
var version = (int)element.Attribute(nameof(SerializationVersion)); | ||
var version = (int)element.Attribute(nameof(SerializationVersion))!; | ||
huoyaoyuan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if (typeAttribute == null || valueAttribute == null || severityAttribute == null) | ||
{ | ||
|
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 it ever possible for
PathUtilities.IsAbsolute(filePath)
to return true butPath.GetDirectoryName(filePath)
to return null? If not, I almost prefer this form: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 path happens to be
C:\
?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.
Yeah, assert seems wise so I think this looks good -- there shouldn't ever be a directory name versus a file path being passed here, but if that were to happen...