Skip to content

Conversation

@jaredpar
Copy link
Member

@jaredpar jaredpar commented Jan 3, 2020

No description provided.

@jaredpar jaredpar requested a review from a team as a code owner January 3, 2020 20:12
@jaredpar
Copy link
Member Author

jaredpar commented Jan 3, 2020

@dotnet/roslyn-compiler PTAL

Copy link
Contributor

@cston cston Jan 3, 2020

Choose a reason for hiding this comment

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

SyntaxNode? [](start = 28, length = 11)

When is this null? #Resolved

Copy link
Member Author

@jaredpar jaredpar Jan 3, 2020

Choose a reason for hiding this comment

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

Most obvious place is here:

        public SyntaxList(IEnumerable<TNode>? nodes)
            : this(CreateNode(nodes)!)

Which ... I should really remove the ! from cause it's unnecessary. #Resolved

Copy link
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

Done with 9/14 files

Copy link
Contributor

@sharwell sharwell Jan 3, 2020

Choose a reason for hiding this comment

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

💡 Consider splitting the expression list.ItemInternal(i) to a local, then asserting that it is not null. #WontFix

Copy link
Contributor

Choose a reason for hiding this comment

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

❔ Is it possible for this to reach external code and still be null?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not that I'm aware of. It's an implementation detail of this type.


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

@jaredpar jaredpar added the Concept-Null Annotations The issue involves annotating an API for nullable reference types label Jan 3, 2020
Copy link
Contributor

@sharwell sharwell Jan 3, 2020

Choose a reason for hiding this comment

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

💡 Consider refactoring this method:

var listNode = builder?.ToListNode();
if (listNode is null)
{
  return null;
}

return new SeparatedSyntaxList<TNode>(new SyntaxNodeOrTokenList(listNode.CreateRed(), 0));

Applies to methods above too. #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.

That would change the return type of the method to be a nullable struct. That's not a trivial change here.


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

Copy link
Member Author

Choose a reason for hiding this comment

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

Did u mean return default?


In reply to: 362974659 [](ancestors = 362974659,362969063)

Copy link
Contributor

@sharwell sharwell Jan 3, 2020

Choose a reason for hiding this comment

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

Yes I meant return default. ToListNode only returns null if the list is empty, so the checks can all be combined. #Resolved

Copy link
Contributor

@sharwell sharwell Jan 3, 2020

Choose a reason for hiding this comment

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

💡 The implementation allows builder to be null. I accounted for this in my suggested refactoring.

Applies to all methods in this type. #Resolved

Copy link
Contributor

@sharwell sharwell left a comment

Choose a reason for hiding this comment

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

Review complete. If the changes in SyntaxListBuilderExtensions.cs are not implemented as part of this pull request, please file an issue for them since it seems like a good improvement to make.

jaredpar and others added 7 commits January 3, 2020 14:12
Co-Authored-By: Sam Harwell <sam@tunnelvisionlabs.com>
The suppression in `SyntaxList` is necessary in order to meet
the API contract. Filed an issue for follow up

dotnet#40733
@333fred
Copy link
Member

333fred commented Jan 3, 2020

            return _builder == null;

This implies _builder should be annotated. Why is it not? #Resolved


Refers to: src/Compilers/Core/Portable/Syntax/SyntaxListBuilder`1.cs:30 in 8e507a5. [](commit_id = 8e507a5, deletion_comment = False)

@cston
Copy link
Contributor

cston commented Jan 3, 2020

        }

Should this use var listNode = builder?.ToListNode(); for consistency with extension methods below?


Refers to: src/Compilers/Core/Portable/Syntax/SyntaxListBuilderExtensions.cs:14 in 8e507a5. [](commit_id = 8e507a5, deletion_comment = False)

@jaredpar
Copy link
Member Author

jaredpar commented Jan 6, 2020

            return _builder == null;

It's a good question. One of the tricky parts of nullability is how we treat reference fields inside struct. Do we annotate for the default case or the case where we assume it's always properly constructed. Our struct implementation also suggest that we struggle with this type of decision. So far I've been leaning towards "annotate for default". In this case I just missed it. Will update.

Overall though I don't think this type of scenario is cut and dry.


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


Refers to: src/Compilers/Core/Portable/Syntax/SyntaxListBuilder`1.cs:30 in 8e507a5. [](commit_id = 8e507a5, deletion_comment = False)

@jaredpar jaredpar merged commit 2cb6d2d into dotnet:master Jan 6, 2020
@jaredpar jaredpar deleted the nullable4.1 branch January 6, 2020 22:04
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