-
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
Annotate more public syntax APIs #44266
Conversation
src/Compilers/CSharp/Portable/Syntax/AnonymousMethodExpressionSyntax.cs
Outdated
Show resolved
Hide resolved
Done review pass (commit 2) #Resolved |
@333fred Please take another look when you get a chance. Thanks |
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 (commit 3)
Thanks Fred! @dotnet/roslyn-compiler for a second review. Cheers |
@@ -72,11 +72,11 @@ public bool IsNull | |||
/// <summary> | |||
/// The value for a non-array constant. | |||
/// </summary> | |||
public object? Value | |||
public object Value |
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.
public object Value [](start = 8, length = 19)
Isn't this null
for the constant 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.
var lambda = lambdaBody.Parent; | ||
if (lambda.Kind() == SyntaxKind.ArrowExpressionClause) | ||
if (lambda.IsKind(SyntaxKind.ArrowExpressionClause)) |
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.
IsKind( [](start = 23, length = 7)
Just curious - why change these? #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.
The lambda.Kind()
on line 63 would warn. Then I think I just aligned the check on line 57 for stylistic consistency.
In reply to: 441899787 [](ancestors = 441899787)
@@ -264,7 +268,7 @@ public override SeparatedSyntaxList<TNode> VisitList<TNode>(SeparatedSyntaxList< | |||
} | |||
else | |||
{ | |||
visited = this.VisitListElement((TNode)item.AsNode()); | |||
visited = this.VisitListElement((TNode?)item.AsNode()); |
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.
(TNode?)item.AsNode() [](start = 60, length = 21)
Can we use node
here? #Closed
@@ -131,7 +132,7 @@ internal T DecodeValue<T>(SpecialType specialType) | |||
return value; | |||
} | |||
|
|||
internal bool TryDecodeValue<T>(SpecialType specialType, [MaybeNull][NotNullWhen(returnValue: true)] out T value) | |||
internal bool TryDecodeValue<T>(SpecialType specialType, [MaybeNull][NotNullWhen(true)] out T value) |
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.
[NotNullWhen(true)] [](start = 76, length = 19)
What if value == null
? #Closed
@@ -141,7 +142,8 @@ internal bool TryDecodeValue<T>(SpecialType specialType, [MaybeNull][NotNullWhen | |||
|
|||
if (_type.SpecialType == specialType || (_type.TypeKind == TypeKind.Enum && specialType == SpecialType.System_Enum)) | |||
{ | |||
value = (T)_value!; | |||
Debug.Assert(_value is object); |
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.
Debug.Assert(_value is object); [](start = 16, length = 31)
Don't we get here with a constant null
? #Closed
@@ -285,11 +285,13 @@ private ObsoleteAttributeData DecodeObsoleteAttribute() | |||
// ObsoleteAttribute(string, bool) | |||
|
|||
Debug.Assert(args.Length <= 2); | |||
message = (string)args[0].ValueInternal; | |||
Debug.Assert(args[0].ValueInternal is object); |
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.
Debug.Assert(args[0].ValueInternal is object); [](start = 16, length = 46)
Could the value be [Obsolete(null)]
? #Closed
@@ -341,8 +343,10 @@ private ObsoleteAttributeData DecodeDeprecatedAttribute() | |||
// DeprecatedAttribute(String, DeprecationType, UInt32, Platform) | |||
// DeprecatedAttribute(String, DeprecationType, UInt32, String) | |||
|
|||
message = (string)args[0].ValueInternal; | |||
isError = ((int)args[1].ValueInternal == 1); | |||
Debug.Assert(args[0].ValueInternal is object); |
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.
Debug.Assert(args[0].ValueInternal is object) [](start = 16, length = 45)
Could the value be [Deprecated(null, ...)]
? #Closed
|
||
namespace Microsoft.CodeAnalysis.CSharp | ||
{ | ||
public static class TypedConstantExtensions | ||
{ | ||
/// <summary> | ||
/// Returns the System.String that represents the current TypedConstant. | ||
/// For testing and debugging only |
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.
For testing and debugging only [](start = 12, length = 30)
This method is part of the public API so I don't think we can state how this method is used. #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.
@@ -140,7 +138,10 @@ private static string DisplayUnsignedEnumConstant(TypedConstant constant, Specia | |||
} | |||
|
|||
// Unable to decode the enum constant, just display the integral value | |||
return constant.ValueInternal.ToString(); | |||
Debug.Assert(constant.ValueInternal is object); |
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.
Debug.Assert(constant.ValueInternal is object) [](start = 12, length = 46)
Why assert rather than using !
? #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.
Because this is the result of a check in a calling method (if (constant.IsNull)
in ToCSharpString
), but not in the present method.
In reply to: 443063994 [](ancestors = 443063994)
@@ -213,7 +214,10 @@ private static string DisplaySignedEnumConstant(TypedConstant constant, SpecialT | |||
} | |||
|
|||
// Unable to decode the enum constant, just display the integral value | |||
return constant.ValueInternal.ToString(); | |||
Debug.Assert(constant.ValueInternal is object); |
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.
Debug.Assert(constant.ValueInternal is object); [](start = 12, length = 47)
Why assert rather than using !
? #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.
message = (string)args[0].ValueInternal; | ||
isError = ((int)args[1].ValueInternal == 1); | ||
Debug.Assert(args[1].ValueInternal is object); | ||
message = (string?)args[0].ValueInternal!; |
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 = 56, length = 1)
!
is incorrect. #Closed
@@ -48,7 +48,7 @@ public XmlFileResolver(string? baseDirectory) | |||
/// If <paramref name="baseFilePath"/> is relative <see cref="BaseDirectory"/> is used as the base path of <paramref name="baseFilePath"/>. | |||
/// </param> | |||
/// <returns>Normalized XML document file path or null if not found.</returns> | |||
public override string? ResolveReference(string path, string? baseFilePath) | |||
public override string? ResolveReference(string? path, string? baseFilePath) |
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.
string? path [](start = 49, length = 12)
Why is path
optional? It looks like the uses of path
support null
values, but allowing null
seems incorrect given the parameter description where it is a path to a source 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.
I'm trying to capture/document the existing behavior of this method.
The test I added does exercise this path. I can adjust the caller instead (don't call if path
is null), but result is same.
In reply to: 443154834 [](ancestors = 443154834)
@@ -27,7 +27,7 @@ protected XmlReferenceResolver() | |||
/// <param name="path">The reference path to resolve. May be absolute or relative path.</param> | |||
/// <param name="baseFilePath">Path of the source file that contains the <paramref name="path"/> (may also be relative), or null if not available.</param> | |||
/// <returns>Path to the XML artifact, or null if the file can't be resolved.</returns> | |||
public abstract string? ResolveReference(string path, string? baseFilePath); | |||
public abstract string? ResolveReference(string? path, string? baseFilePath); |
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.
string? path [](start = 49, length = 12)
Why is path
optional? #Resolved
No description provided.