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

Annotate more public syntax APIs #44266

Merged
merged 9 commits into from
Jun 23, 2020
Merged

Annotate more public syntax APIs #44266

merged 9 commits into from
Jun 23, 2020

Conversation

jcouv
Copy link
Member

@jcouv jcouv commented May 14, 2020

No description provided.

@jcouv jcouv added Area-Compilers Concept-Null Annotations The issue involves annotating an API for nullable reference types labels May 14, 2020
@jcouv jcouv self-assigned this May 14, 2020
@jcouv jcouv marked this pull request as ready for review May 15, 2020 18:06
@jcouv jcouv requested review from a team as code owners May 15, 2020 18:06
@333fred
Copy link
Member

333fred commented May 19, 2020

Done review pass (commit 2) #Resolved

@jcouv jcouv requested a review from 333fred May 21, 2020 18:29
@jcouv
Copy link
Member Author

jcouv commented May 26, 2020

@333fred Please take another look when you get a chance. Thanks

Copy link
Member

@333fred 333fred left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM (commit 3)

@jcouv
Copy link
Member Author

jcouv commented May 27, 2020

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
Copy link
Member

@cston cston Jun 17, 2020

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I'd misread the assertion in constructor.


In reply to: 441893234 [](ancestors = 441893234)

@cston
Copy link
Member

cston commented Jun 17, 2020

    internal object ValueInternal

object?? #Closed


Refers to: src/Compilers/Core/Portable/Symbols/TypedConstant.cs:93 in d801f2a. [](commit_id = d801f2a, deletion_comment = False)

var lambda = lambdaBody.Parent;
if (lambda.Kind() == SyntaxKind.ArrowExpressionClause)
if (lambda.IsKind(SyntaxKind.ArrowExpressionClause))
Copy link
Member

@cston cston Jun 18, 2020

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

Copy link
Member Author

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());
Copy link
Member

@cston cston Jun 18, 2020

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)
Copy link
Member

@cston cston Jun 19, 2020

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);
Copy link
Member

@cston cston Jun 19, 2020

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);
Copy link
Member

@cston cston Jun 19, 2020

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);
Copy link
Member

@cston cston Jun 19, 2020

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
Copy link
Member

@cston cston Jun 19, 2020

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks


In reply to: 443063564 [](ancestors = 443063564)

@@ -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);
Copy link
Member

@cston cston Jun 19, 2020

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

Copy link
Member Author

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);
Copy link
Member

@cston cston Jun 19, 2020

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

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same rationale


In reply to: 443064067 [](ancestors = 443064067)

message = (string)args[0].ValueInternal;
isError = ((int)args[1].ValueInternal == 1);
Debug.Assert(args[1].ValueInternal is object);
message = (string?)args[0].ValueInternal!;
Copy link
Member

@cston cston Jun 20, 2020

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)
Copy link
Member

@cston cston Jun 20, 2020

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

Copy link
Member Author

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);
Copy link
Member

@cston cston Jun 20, 2020

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

@jcouv jcouv merged commit 9a658fa into dotnet:master Jun 23, 2020
@ghost ghost added this to the Next milestone Jun 23, 2020
@jcouv jcouv deleted the annotate-more6 branch June 23, 2020 23:33
@dibarbet dibarbet modified the milestones: Next, 16.7.P4 Jun 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Concept-Null Annotations The issue involves annotating an API for nullable reference types
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants