Skip to content

Add a prototype implementation for GetTypeInfo(PatternSyntax)#26521

Merged
gafter merged 3 commits intodotnet:features/recursive-patternsfrom
gafter:rpatterns-GetTypeInfo
May 1, 2018
Merged

Add a prototype implementation for GetTypeInfo(PatternSyntax)#26521
gafter merged 3 commits intodotnet:features/recursive-patternsfrom
gafter:rpatterns-GetTypeInfo

Conversation

@gafter
Copy link
Copy Markdown
Member

@gafter gafter commented Apr 30, 2018

This is a first draft of #26494, and requires more testing.

This is a first draft of dotnet#26494, and requires more testing.
@gafter gafter added Area-Compilers Feature Request 4 - In Review A fix for the issue is submitted for review. Feature - Pattern Matching Pattern Matching labels Apr 30, 2018
@gafter gafter added this to the 16.0 milestone Apr 30, 2018
@gafter gafter self-assigned this Apr 30, 2018
@gafter gafter requested review from agocke, cston and jcouv April 30, 2018 22:25
@gafter gafter requested a review from a team as a code owner April 30, 2018 22:25
<Field Name="DeconstructMethodOpt" Type="MethodSymbol" Null="allow"/>
<Field Name="Deconstruction" Type="ImmutableArray&lt;BoundPattern&gt;" Null="allow"/>
<Field Name="PropertiesOpt" Type="ImmutableArray&lt;(Symbol symbol, BoundPattern pattern)&gt;" Null="allow"/>
<Field Name="Deconstruction" Type="ImmutableArray&lt;BoundSubpattern&gt;" Null="allow"/>
Copy link
Copy Markdown
Member

@jcouv jcouv Apr 30, 2018

Choose a reason for hiding this comment

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

Not related to this PR: should Deconstruction be called DeconstructionOpt? #Resolved

Copy link
Copy Markdown
Member Author

@gafter gafter May 1, 2018

Choose a reason for hiding this comment

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

We are inconsistent about that. I think we should do a sweep to some consistent state. #Resolved

</Node>

<Node Name="BoundSubpattern" Base="BoundNode">
<Field Name="Symbol" Type="Symbol" Null="allow"/>
Copy link
Copy Markdown
Member

@jcouv jcouv Apr 30, 2018

Choose a reason for hiding this comment

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

Maybe add a comment. #Resolved

TypeSymbol elementType = isError ? CreateErrorType() : elementTypes[i];
BoundPattern boundSubpattern = BindVarDesignation(node, tupleDesignation.Variables[i], elementType, isError, diagnostics);
patterns.Add(boundSubpattern);
subPatterns.Add(new BoundSubpattern(node, null, boundSubpattern));
Copy link
Copy Markdown
Member

@jcouv jcouv Apr 30, 2018

Choose a reason for hiding this comment

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

Nit: name null here and below. #Resolved

@jcouv
Copy link
Copy Markdown
Member

jcouv commented Apr 30, 2018

        if (recursive.PropertiesOpt != null)

Not related to this PR: PropertiesOpt is an immutable array. Why are we checking against null? #Resolved


Refers to: src/Compilers/CSharp/Portable/Binder/DecisionDagBuilder.cs:457 in 3ae4026. [](commit_id = 3ae4026, deletion_comment = False)

BoundNode highestBoundNode,
BoundNode boundNodeForSyntacticParent)
{
if (lowestBoundNode is BoundPattern pat)
Copy link
Copy Markdown
Member

@jcouv jcouv Apr 30, 2018

Choose a reason for hiding this comment

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

Nit: pattern can be spelled out #Resolved

Copy link
Copy Markdown
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

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

LGTM with some nits

Assert.Equal(ex.Type, typeInfo.Type.ToTestDisplayString());
Assert.Equal(ex.ConvertedType, typeInfo.ConvertedType.ToTestDisplayString());
}
Assert.Equal(expected.Length, i);
Copy link
Copy Markdown
Member

@jcouv jcouv Apr 30, 2018

Choose a reason for hiding this comment

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

Could you add testing of GetTypeInfo to some existing types tests as well? #ByDesign

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, but not this round. I'm keeping the bug for this new API open until testing is more complete.


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

@gafter
Copy link
Copy Markdown
Member Author

gafter commented May 1, 2018

@cston @agocke Could one of you please provide a second review of this?

/// <summary>
/// Helper class to remove alias qualifications.
/// </summary>
class RemoveAliasQual : CSharpSyntaxRewriter
Copy link
Copy Markdown
Contributor

@cston cston May 1, 2018

Choose a reason for hiding this comment

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

Please consider spelling out Qualifiers. #Resolved

foundField = CheckIsTupleElement(subPattern.NameColon.Name, (NamedTypeSymbol)declType, name, i, diagnostics);
// PROTOTYPE(patterns2): Should the tuple field binding for the name be stored somewhere in the node?

}
Copy link
Copy Markdown
Contributor

@cston cston May 1, 2018

Choose a reason for hiding this comment

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

Unnecessary blank line. #Resolved

@jcouv
Copy link
Copy Markdown
Member

jcouv commented May 1, 2018

Please merge latest patterns changes into features/build-demo once this PR is merged. I'll need this API for IDE logic. Thanks

var ex = expected[i++];
Assert.Equal(ex.Source, pat.ToString());
Assert.Equal(ex.Type, typeInfo.Type.ToTestDisplayString());
Assert.Equal(ex.ConvertedType, typeInfo.ConvertedType.ToTestDisplayString());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@gafter Another general discussion: could we reconsider factoring PropertyPatternSyntax (with a type, property sub-pattern and designation) and DeconstructionPatternSyntax (with the same plus parens and list of patterns)?

The parens and list of patterns are pulled into a deconstruction sub-pattern. Then we can have one node with optional type, optional positional sub-pattern and optional property sub-pattern.

I understand that you wanted to have the syntax nodes enforce some constraints (you can't be missing the type, positional and property sub-patterns).

But on the other hand, my experience dealing with the syntax API so far is that it would be easier to deal with and reason about.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

what about exposing their common properties through an abstract base class (Type, PropertySubpattern, Designation)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@gafter gafter merged commit ce81a76 into dotnet:features/recursive-patterns May 1, 2018
@gafter gafter removed the 4 - In Review A fix for the issue is submitted for review. label Dec 18, 2018
@gafter gafter removed the 4 - In Review A fix for the issue is submitted for review. label Dec 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants